Intl.PluralRules

对象的英文请立即获取iTunes多种敏感格式状语从句:多种语言规则对象的构造函数。Intl.PluralRules

句法

new Intl.PluralRules([locales[, options]]) Intl.PluralRules.call(this[, locales[, options]])

参数

locales

可选的。一个带有BCP 47语言标签的字符串或这种字符串的数组。有关参数的一般形式和解释locales,请参阅Intl page

options

可选的,具有部分或全部以下属性的对象:

localeMatcher
要使用的语言环境匹配算法。可能的值是"lookup""best fit"; 默认是"best fit"有关此选项的信息,请参阅Intl page
type
要使用的类型。可能的值是:
  • "cardinal"对于基数(指的是事物的数量)。这是默认值。
  • "ordinal" 对于序号(指的是事物的排序或排名,例如英文中的“1st”,“2nd”,“3rd”)。

描述

属性

Intl.PluralRules.prototype
允许为所有对象添加属性。

方法

Intl.PluralRules.supportedLocalesOf()
返回一个数组,其中包含提供的语言环境的支持,而不必回退到运行时的默认语言环境。

PluralRules 实例

属性

PluralRules 实例从其原型继承了以下属性:

方法

PluralRules 实例从它们的原型继承了以下方法:

例子

基本用法

在没有指定语言环境的基本使用中,返回默认语言环境中的格式化字符串和默认选项这有助于区分单数和复数形式,例如“dog”和“dogs”。

var pr = new Intl.PluralRules();

pr.select(0);
// → 'other' if in US English locale

pr.select(1);
// → 'one' if in US English locale

pr.select(2);
// → 'other' if in US English locale

运用 locales

这个例子展示了局部复数规则的一些变化。为了获得应用程序用户界面中使用的语言格式,请确保使用locales参数指定该语言(可能还有一些备用语言)

// Arabic has different plural rules

new Intl.PluralRules('ar-EG').select(0);
// → 'zero'
new Intl.PluralRules('ar-EG').select(1); 
// → 'one'
new Intl.PluralRules('ar-EG').select(2);
// → 'two'
new Intl.PluralRules('ar-EG').select(6);
// → 'few'
new Intl.PluralRules('ar-EG').select(18);
// → 'many'

运用 options

可以查询查询结果使用options参数进行自定义,该参数具有一个type您可以设置的属性ordinal这对计算序数指标很有用,例如“第一”,“第二”,“第三”,“第四”,“42”等。

var pr = new Intl.PluralRules('en-US', { type: 'ordinal' });

pr.select(0);
// → 'other'
pr.select(1);
// → 'one'
pr.select(2);
// → 'two'
pr.select(3);
// → 'few'
pr.select(4);
// → 'other'
pr.select(42);
// → 'two'

规范

规范 状态 评论
国际复数规则草案 Living Standard 初始定义

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
PluralRulesChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0nodejs Full support 10.0.0
Notes
Full support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the PluralRules() constructor for more details.
PluralRules() constructorChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0nodejs Full support 13.0.0
Full support 13.0.0
Partial support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the PluralRules instance silently falls back to en-US. To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
resolvedOptionsChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0nodejs Full support 10.0.0
Notes
Full support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the PluralRules() constructor for more details.
selectChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0nodejs Full support 10.0.0
Notes
Full support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the PluralRules() constructor for more details.
supportedLocalesOfChrome Full support 63Edge Full support 18Firefox Full support 58IE No support NoOpera Full support 50Safari Full support 13WebView Android Full support 63Chrome Android Full support 63Firefox Android Full support 58Opera Android Full support 46Safari iOS Full support 13Samsung Internet Android Full support 8.0nodejs Full support 10.0.0
Notes
Full support 10.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the PluralRules() constructor for more details.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

也可以看看