Intl.PluralRules()
constructor creates
Intl.PluralRules
对象。
new Intl.PluralRules([locales[, options]])
locales
Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the
locales
argument, see the
Intl page
.
options
Optional. An object with some or all of the following properties:
localeMatcher
"lookup"
and
"best fit"
; the default is
"best fit"
. For information about this option, see the
Intl page
.
type
"cardinal"
for cardinal numbers (refering to the quantity of things). This is the default value.
"ordinal"
for ordinal number (refering to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English).
The following properties fall into two groups:
minimumIntegerDigits
,
minimumFractionDigits
,和
maximumFractionDigits
in one group,
minimumSignificantDigits
and
maximumSignificantDigits
in the other. If at least one property from the second group is defined, then the first group is ignored.
minimumIntegerDigits
The minimum number of integer digits to use. Possible values are from 1 to 21; the default is 1.
minimumFractionDigits
maximumFractionDigits
minimumFractionDigits
and 3; the default for currency formatting is the larger of
minimumFractionDigits
and the number of minor unit digits provided by the
ISO 4217 currency code list
(2 if the list doesn't provide that information); the default for percent formatting is the larger of
minimumFractionDigits
and 0.
minimumSignificantDigits
The minimum number of significant digits to use. Possible values are from 1 to 21; the default is 1.
maximumSignificantDigits
The maximum number of significant digits to use. Possible values are from 1 to 21; the default is 21.
In basic use without specifying a locale, a formatted string in the default locale and with default options is returned. This is useful to distinguish between singular and plural forms, e.g. "dog" and "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
The results can be customized using the
options
argument, which has one property called
type
which you can set to
ordinal
. This is useful to figure out the ordinal indicator, e.g. "1st", "2nd", "3rd", "4th", "42nd" and so forth.
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'
| 规范 |
|---|
|
ECMAScript 国际化 API (ECMA-402)
The definition of 'Intl.PluralRules() constructor' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PluralRules()
构造函数
|
Chrome 63 | Edge 18 | Firefox 58 | IE No | Opera 50 | Safari 13 | WebView Android 63 | Chrome Android 63 | Firefox Android 58 | Opera Android 46 | Safari iOS 13 | Samsung Internet Android 8.0 |
nodejs
13.0.0
|
完整支持
不支持
见实现注意事项。
Intl
Collator
DateTimeFormat
ListFormat
NumberFormat
PluralRules
RelativeTimeFormat
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()