Featureadvanced
Plural rules
Also called Intl.PluralRules, plural categories, cardinal and ordinal plurals, ordinal suffixes in JavaScript, selectRange, pluralization.
Intl.PluralRules maps a number to the plural category a locale uses for it, one of zero, one, two, few, many and other, for counts or for ordinals. The program picks the words for each category.
- Language
- JavaScript
Synopsis
const en = new Intl.PluralRules("en-US");
console.log([0, 1, 2, 1.5].map((n) => en.select(n)));
const ar = new Intl.PluralRules("ar-EG");
console.log([0, 1, 2, 6, 18, 100].map((n) => ar.select(n)));
console.log(new Intl.PluralRules("zh").select(1), en.resolvedOptions().pluralCategories);
[ 'other', 'one', 'other', 'other' ]
[ 'zero', 'one', 'two', 'few', 'many', 'other' ]
other [ 'one', 'other' ]
| Call | Result |
|---|---|
new Intl.PluralRules(locale) |
rules for counts (type: "cardinal") |
new Intl.PluralRules(locale, { type: "ordinal" }) |
rules for 1st, 2nd, 3rd |
rules.select(n) |
one of zero, one, two, few, many, other |
rules.selectRange(a, b) |
the category for a range |
rules.resolvedOptions().pluralCategories |
the categories the locale uses |
Semantics
r1. "The Intl.PluralRules object is useful for selecting the correct plural form of a word. It doesn't automatically pluralize words for you (for example, you can't pass it "apple" and expect "apples" back), but it tells you which plural form to use based on a number."1 select(number) returns "A string representing the pluralization category of the number".2 The program keeps one word or message per category and looks it up with the result. Example: basics.
r2. "The full set of tags that might be returned are: zero , one , two , few , many , and other (the "general" plural form, also used if the language only has one form)."3 Languages differ: "English has two forms for expressing cardinal numbers", "while Chinese has only one form, and Arabic has six!"3 resolvedOptions().pluralCategories lists "all possible results of PluralRuleSelect for the selected locale".4
r3. The type option is cardinal, the default, "For cardinal numbers (referring to the quantity of things)", or ordinal, "For ordinal number (referring to the ordering or ranking of things".5 For English ordinals, select() "can return any of four tags", one for each of the endings st, nd, rd and th.3 Example: ordinal.
r4. The category depends on how the number is written, not only on its value: "The plural form of the specified number may also depend on constructor options , such as how the number is rounded".3 The constructor takes the digit options of Intl.NumberFormat, such as minimumFractionDigits.5 In ECMA-402 the operation that picks the category takes the number as "s (a decimal String)".4 Example: digits.
r5. selectRange() "receives two values and returns a string indicating which plural rule to use for locale-aware formatting of the indicated range."6 "In English there is only one plural form, such as "1–10 apples", and the method will return other . Other languages can have many forms."6 Example: range.
r6. Intl.PluralRules must be called with new. Its constructor begins: "If NewTarget is undefined, throw a TypeError exception."4 Example: nonew.
Examples
Ordinal suffixes in English (rule r3).
const pr = new Intl.PluralRules("en-US", { type: "ordinal" });
const suffixes = new Map([["one", "st"], ["two", "nd"], ["few", "rd"], ["other", "th"]]);
const ordinal = (n) => `${n}${suffixes.get(pr.select(n))}`;
console.log([0, 1, 2, 3, 4, 11, 12, 13, 21, 42, 103].map(ordinal).join(" "));
0th 1st 2nd 3rd 4th 11th 12th 13th 21st 42nd 103rd
The same number shown as 1 and as 1.0 (rule r4).
const plain = new Intl.PluralRules("en");
const oneDecimal = { minimumFractionDigits: 1 };
const fixed = new Intl.PluralRules("en", oneDecimal);
console.log(plain.select(1), fixed.select(1));
console.log(new Intl.NumberFormat("en", oneDecimal).format(1));
one other
1.0
With one fraction digit the number is shown as 1.0, and the English rules put that in other. Give the rules the same digit options as the formatter that shows the number.
Ranges (rule r5).
console.log(new Intl.PluralRules("en").selectRange(1, 10));
console.log(new Intl.PluralRules("sl").selectRange(102, 201));
console.log(new Intl.PluralRules("pt").selectRange(102, 102));
other
few
other
Pitfalls
Choosing the form with n === 1
This code runs but gives a wrong answer on purpose.
const byHand = (n) => (n === 1 ? "one" : "other");
const pl = new Intl.PluralRules("pl");
const counts = [1, 2, 5, 22, 25];
console.log(counts.map(byHand));
console.log(counts.map((n) => pl.select(n)));
[ 'one', 'other', 'other', 'other', 'other' ]
[ 'one', 'few', 'many', 'few', 'many' ]
The test works for English and fails for languages with more forms. MDN: the hand-written test "is hard to generalize across languages, especially those with many plural forms."1 Ask the rules for the category (rule r2).
Calling Intl.PluralRules without new
This code runs but gives a wrong answer on purpose.
console.log(typeof Intl.Collator("en").compare);
try {
Intl.PluralRules("en");
} catch (e) {
console.log(e.name);
}
function
TypeError
The Intl.Collator constructor goes on without new: "If NewTarget is undefined, let newTarget be the active function object".4 Intl.PluralRules throws (rule r6).
Comparison
Python's gettext.ngettext takes a singular, a plural and a number, and when a translation is found it applies "the plural formula to n"; "If no translation is found, return singular if n is 1; return plural otherwise."7 Java's ChoiceFormat attaches "a format to a range of numbers" and "is generally used in a MessageFormat for handling plurals", but "ChoiceFormat doesn't implement any locale specific behavior."8 JavaScript gives the category from the locale data (rule r2) and leaves the words to the program (rule r1). See Formatting data.
References
- MDN Web Docs, JavaScript Guide, Internationalization, Plural rules
- MDN Web Docs, JavaScript Reference, Intl.PluralRules.prototype.select(), Return value; Examples
- MDN Web Docs, JavaScript Reference, Intl.PluralRules, the introduction; Description
- ECMAScript 2026 Internationalization API Specification (ECMA-402, 13th edition), 17.1.1 Intl.PluralRules; 17.3.2 Intl.PluralRules.prototype.resolvedOptions; 17.5.1 PluralRuleSelect
- MDN Web Docs, JavaScript Reference, Intl.PluralRules() constructor, Parameters; type
- MDN Web Docs, JavaScript Reference, Intl.PluralRules.prototype.selectRange(), the introduction; Description
- The Python Standard Library, Python 3.14, gettext, gettext.ngettext
- Java SE 25 API, Class ChoiceFormat, the class description
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W3 standard |
|
Tag 7C7DXB Edit this page History Report an error Markdown