npm install intl-plural-rules-polyfill --save
If you're not using a bundler then use a standalone version from a CDN.
const pluralRules = "en"style: "cardinal" // "cardinal" is the default. Other options: "ordinal".pluralRules // "other"pluralRules // "one"
The possible return values are:
For more info on which is which read the official Unicode CLDR documentation. Unicode CLDR (Common Locale Data Repository) is an industry standard and is basically a collection of formatting rules for all locales (date, time, currency, measurement units, numbers, etc).
If the app only uses
"cardinals" type and doesn't use
"ordinals" then the polyfill can be imported as "cardinals"-only.
Under the hood
To determine whether a number is
make-plural. These rules are number quantifying functions (one for each locale) which can tell if a number should be treated as
other. Knowing how these pluralization rules work is not required but anyway here are some links for curious advanced readers: rules explanation, list of rules for all locales, list of rules for all locales in JSON format (part of
Plural rule functions (
./source/cardinals.js) are generated by running:
npm install make-plural@latest --save-devnpm run generate
[version] is an npm package version range (for example,