Sie lesen die englische Version dieses Inhalts, da für dieses Gebietsschema noch keine Übersetzung vorhanden ist. Helfen Sie uns, diesen Artikel zu übersetzen!
The Intl.PluralRules object is a constructor for objects that enable plural sensitive formatting and plural language language rules.
Syntax
new Intl.PluralRules([locales[, options]])
Intl.PluralRules.call(this[, locales[, options]])
Parameters
locales-
Optional. A string with a BCP 47 language tag, or an array of such strings. For the general form and interpretation of the
localesargument, see the Intl page. options-
Optional. An object with some or all of the following properties:
localeMatcher- The locale matching algorithm to use. Possible values are
"lookup"and"best fit"; the default is"best fit". For information about this option, see the Intl page. type- The type to use. Possible values are:
"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).
Description
Properties
Intl.PluralRules.prototype- Allows the addition of properties to all objects.
Methods
Intl.PluralRules.supportedLocalesOf()- Returns an array containing those of the provided locales that are supported without having to fall back to the runtime's default locale.
PluralRules instances
Properties
PluralRules instances inherit the following properties from their prototype:
Intl.PluralRules.prototype.constructor- A reference to
Intl.PluralRules.
Methods
PluralRules instances inherit the following methods from their prototype:
Intl.PluralRules.prototype.resolvedOptions()- Returns a new object with properties reflecting the locale and collation options computed during initialization of the object.
Intl.PluralRules.prototype.select()- Returns a
Stringindicating which plural rule to use for locale-aware formatting.
Examples
Basic usage
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
Using locales
This example shows some of the variations in localized plural rules. In order to get the format of the language used in the user interface of your application, make sure to specify that language (and possibly some fallback languages) using the locales argument:
// 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'
Using options
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'
Specifications
| Specification | Status | Comment |
|---|---|---|
| Intl Plural Rules Draft | Entwurf | Initial definition |
Browser compatibility
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
PluralRules | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
PluralRules() constructor | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
prototype | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
resolvedOptions | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
select | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
supportedLocalesOf | Chrome Vollständige Unterstützung 63 | Edge Vollständige Unterstützung 18 | Firefox Vollständige Unterstützung 58 | IE Keine Unterstützung Nein | Opera Vollständige Unterstützung 50 | Safari Keine Unterstützung Nein | WebView Android Vollständige Unterstützung 63 | Chrome Android Vollständige Unterstützung 63 | Firefox Android Vollständige Unterstützung 58 | Opera Android Vollständige Unterstützung 46 | Safari iOS Keine Unterstützung Nein | Samsung Internet Android Vollständige Unterstützung 8.0 | nodejs Vollständige Unterstützung 10.0.0 |
Legende
- Vollständige Unterstützung
- Vollständige Unterstützung
- Keine Unterstützung
- Keine Unterstützung
See also
- Introduction: The ECMAScript Internationalization API
- Constructors
- Methods