1 PluralRules Objects

1.1 Abstract Operations for PluralRules Objects

1.1.1 InitializePluralRules ( pluralRules, locales, options )

The abstract operation InitializePluralRules accepts the arguments pluralRules (which must be an object), locales, and options. It initializes pluralRules as a PluralRules object. The following steps are taken:

  1. Let requestedLocales be ? CanonicalizeLocaleList(locales).
  2. Set options to ? CoerceOptionsToObject(options).
  3. Let opt be a new Record.
  4. Let matcher be ? GetOption(options, "localeMatcher", "string", « "lookup", "best fit" », "best fit").
  5. Set opt.[[localeMatcher]] to matcher.
  6. Let t be ? GetOption(options, "type", "string", « "cardinal", "ordinal" », "cardinal").
  7. Set pluralRules.[[Type]] to t.
  8. Perform ? SetNumberFormatDigitOptions(pluralRules, options, +0𝔽, 3𝔽, "standard").
  9. Let localeData be %PluralRules%.[[LocaleData]].
  10. Let r be ResolveLocale(%PluralRules%.[[AvailableLocales]], requestedLocales, opt, %PluralRules%.[[RelevantExtensionKeys]], localeData).
  11. Set pluralRules.[[Locale]] to the value of r.[[locale]].
  12. Return pluralRules.

1.1.2 GetOperands ( s )

When the GetOperands abstract operation is called with argument s, it performs the following steps:

  1. Assert: Type(s) is String.
  2. Let n be ! ToNumber(s).
  3. Assert: n is finite.
  4. Let dp be ! StringIndexOf(s, ".", 0).
  5. If dp = -1, then
    1. Set iv to n.
    2. Let f be 0.
    3. Let v be 0.
  6. Else,
    1. Let iv be the substring of s from position 0, inclusive, to position dp, exclusive.
    2. Let fv be the substring of s from position dp, exclusive, to the end of s.
    3. Let f be ! ToNumber(fv).
    4. Let v be the length of fv.
  7. Let i be abs(! ToNumber(iv)).
  8. If f ≠ 0, then
    1. Let ft be the value of fv stripped of trailing "0".
    2. Let w be the length of ft.
    3. Let t be ! ToNumber(ft).
  9. Else,
    1. Let w be 0.
    2. Let t be 0.
  10. Return a new Record { [[Number]]: n, [[IntegerDigits]]: i, [[NumberOfFractionDigits]]: v, [[NumberOfFractionDigitsWithoutTrailing]]: w, [[FractionDigits]]: f, [[FractionDigitsWithoutTrailing]]: t }.
Table 1: Plural Rules Operands Record Fields
Internal Slot Type Description
[[Number]] Number Absolute value of the source number (integer and decimals)
[[IntegerDigits]] Number Number of digits of [[Number]].
[[NumberOfFractionDigits]] Number Number of visible fraction digits in [[Number]], with trailing zeroes.
[[NumberOfFractionDigitsWithoutTrailing]] Number Number of visible fraction digits in [[Number]], without trailing zeroes.
[[FractionDigits]] Number Number of visible fractional digits in [[Number]], with trailing zeroes.
[[FractionDigitsWithoutTrailing]] Number Number of visible fractional digits in [[Number]], without trailing zeroes.

1.1.3 PluralRuleSelect ( locale, type, n, operands )

When the PluralRuleSelect abstract operation is called with four arguments, it performs an implementation-dependent algorithm to map n to the appropriate plural representation of the Plural Rules Operands Record operands by selecting the rules denoted by type for the corresponding locale, or the String value "other".

1.1.4 ResolvePlural ( pluralRules, n )

When the ResolvePlural abstract operation is called with arguments pluralRules (which must be an object initialized as a PluralRules) and n (which must be a Number value), it returns a String value representing the plural form of n according to the effective locale and the options of pluralRules. The following steps are taken:

  1. Assert: Type(pluralRules) is Object.
  2. Assert: pluralRules has an [[InitializedPluralRules]] internal slot.
  3. Assert: Type(n) is Number.
  4. If n is not a finite Number, then
    1. Return "other".
  5. Let locale be pluralRules.[[Locale]].
  6. Let type be pluralRules.[[Type]].
  7. Let res be ! FormatNumericToString(pluralRules, n).
  8. Let s be res.[[FormattedString]].
  9. Let operands be ! GetOperands(s).
  10. Return ! PluralRuleSelect(locale, type, n, operands).

1.1.5 PluralRuleSelectRange ( locale, type, xp, yp )

When the PluralRuleSelectRange abstract operation is called with four arguments, it performs an implementation-dependent algorithm to map the plural form String values xp and yp, representing the plural forms of the start and end of a range, to a resolved String value for the plural form of the range as a whole denoted by type for the corresponding locale, or the String value "other".

1.1.6 ResolvePluralRange ( pluralRules, x, y )

When the ResolvePluralRange abstract operation is called with arguments pluralRules (which must be an object initialized as a PluralRules), x (which must be a Number value), and y (which must be a Number value), it returns a String value representing the plural form of the range starting from x and ending at y according to the effective locale and the options of pluralRules. The following steps are taken:

  1. Assert: Type(pluralRules) is Object.
  2. Assert: pluralRules has an [[InitializedPluralRules]] internal slot.
  3. Assert: Type(x) is Number.
  4. Assert: Type(y) is Number.
  5. If x is NaN or y is NaN, throw a RangeError exception.
  6. Let xp be ! ResolvePlural(pluralRules, x).
  7. Let yp be ! ResolvePlural(pluralRules, y).
  8. Let locale be pluralRules.[[Locale]].
  9. Let type be pluralRules.[[Type]].
  10. Return ! PluralRuleSelectRange(locale, type, xp, yp).

1.2 The Intl.PluralRules Constructor

The PluralRules constructor is the %PluralRules% intrinsic object and a standard built-in property of the Intl object. Behaviour common to all service constructor properties of the Intl object is specified in .

1.2.1 Intl.PluralRules ( [ locales [ , options ] ] )

When the Intl.PluralRules function is called with optional arguments locales and options, the following steps are taken:

  1. If NewTarget is undefined, throw a TypeError exception.
  2. Let pluralRules be ? OrdinaryCreateFromConstructor(NewTarget, "%PluralRules.prototype%", « [[InitializedPluralRules]], [[Locale]], [[Type]], [[MinimumIntegerDigits]], [[MinimumFractionDigits]], [[MaximumFractionDigits]], [[MinimumSignificantDigits]], [[MaximumSignificantDigits]], [[RoundingType]] »).
  3. Return ? InitializePluralRules(pluralRules, locales, options).

1.3 Properties of the Intl.PluralRules Constructor

The Intl.PluralRules constructor has the following properties:

1.3.1 Intl.PluralRules.prototype

The value of Intl.PluralRules.prototype is %PluralRules.prototype%.

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.

1.3.2 Intl.PluralRules.supportedLocalesOf ( locales [ , options ] )

When the supportedLocalesOf method is called with arguments locales and options, the following steps are taken:

  1. Let availableLocales be %PluralRules%.[[AvailableLocales]].
  2. Let requestedLocales be ? CanonicalizeLocaleList(locales).
  3. Return ? SupportedLocales(availableLocales, requestedLocales, options).

The value of the "length" property of the supportedLocalesOf method is 1.

1.3.3 Internal slots

The value of the [[AvailableLocales]] internal slot is implementation-defined within the constraints described in .

The value of the [[RelevantExtensionKeys]] internal slot is « ».

Note 1
Unicode Technical Standard 35 describes no locale extension keys that are relevant to the pluralization process.

The value of the [[LocaleData]] internal slot is implementation-defined within the constraints described in .

Note 2
It is recommended that implementations use the locale data provided by the Common Locale Data Repository (available at http://cldr.unicode.org).

1.4 Properties of the Intl.PluralRules Prototype Object

The Intl.PluralRules prototype object is itself an ordinary object. %PluralRules.prototype% is not an Intl.PluralRules instance and does not have an [[InitializedPluralRules]] internal slot or any of the other internal slots of Intl.PluralRules instance objects.

1.4.1 Intl.PluralRules.prototype.constructor

The initial value of Intl.PluralRules.prototype.constructor is the intrinsic object %PluralRules%.

1.4.2 Intl.PluralRules.prototype [ @@toStringTag ]

The initial value of the @@toStringTag property is the String value "Intl.PluralRules".

This property has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: true }.

1.4.3 Intl.PluralRules.prototype.select ( value )

When the select method is called with an argument value, the following steps are taken:

  1. Let pr be the this value.
  2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
  3. Let n be ? ToNumber(value).
  4. Return ! ResolvePlural(pr, n).

1.4.4 Intl.PluralRules.prototype.selectRange ( start, end )

When the selectRange method is called with arguments start and end, the following steps are taken:

  1. Let pr be the this value.
  2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
  3. If start is undefined or end is undefined, throw a TypeError exception.
  4. Let x be ? ToNumber(start).
  5. Let y be ? ToNumber(end).
  6. Return ? ResolvePluralRange(pr, x, y).

1.4.5 Intl.PluralRules.prototype.resolvedOptions ( )

This function provides access to the locale and options computed during initialization of the object.

  1. Let pr be the this value.
  2. Perform ? RequireInternalSlot(pr, [[InitializedPluralRules]]).
  3. Let options be ! OrdinaryObjectCreate(%Object.prototype%).
  4. For each row of Table 2, except the header row, in table order, do
    1. Let p be the Property value of the current row.
    2. Let v be the value of pr's internal slot whose name is the Internal Slot value of the current row.
    3. If v is not undefined, then
      1. Perform ! CreateDataPropertyOrThrow(options, p, v).
  5. Let pluralCategories be a List of Strings representing the possible results of PluralRuleSelect for the selected locale pr.[[Locale]]. This List consists of unique String values, from the the list "zero", "one", "two", "few", "many" and "other", that are relevant for the locale whose localization is specified in LDML Language Plural Rules.
  6. Perform ! CreateDataProperty(options, "pluralCategories", CreateArrayFromList(pluralCategories)).
  7. If pr.[[RoundingType]] is morePrecision, then
    1. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "morePrecision").
  8. Else if pr.[[RoundingType]] is lessPrecision, then
    1. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "lessPrecision").
  9. Else,
    1. Perform ! CreateDataPropertyOrThrow(options, "roundingPriority", "auto").
  10. Return options.
Table 2: Resolved Options of PluralRules Instances
Internal Slot Property
[[Locale]] "locale"
[[Type]] "type"
[[MinimumIntegerDigits]] "minimumIntegerDigits"
[[MinimumFractionDigits]] "minimumFractionDigits"
[[MaximumFractionDigits]] "maximumFractionDigits"
[[MinimumSignificantDigits]] "minimumSignificantDigits"
[[MaximumSignificantDigits]] "maximumSignificantDigits"

1.5 Properties of Intl.PluralRules Instances

Intl.PluralRules instances are ordinary objects that inherit properties from %PluralRules.prototype%.

Intl.PluralRules instances have an [[InitializedPluralRules]] internal slot.

Intl.PluralRules instances also have several internal slots that are computed by the constructor:

  • [[Locale]] is a String value with the language tag of the locale whose localization is used by the plural rules.
  • [[Type]] is one of the String values "cardinal" or "ordinal", identifying the plural rules used.
  • [[MinimumIntegerDigits]] is a non-negative integer Number value indicating the minimum integer digits to be used.
  • [[MinimumFractionDigits]] and [[MaximumFractionDigits]] are non-negative integer Number values indicating the minimum and maximum fraction digits to be used. Numbers will be rounded or padded with trailing zeroes if necessary.
  • [[MinimumSignificantDigits]] and [[MaximumSignificantDigits]] are positive integer Number values indicating the minimum and maximum fraction digits to be used. Either none or both of these properties are present; if they are, they override minimum and maximum integer and fraction digits.
  • [[RoundingType]] is one of the values fractionDigits, or significantDigits, morePrecision, or lessPrecision, indicating which rounding strategy to use, as discussed in .