The rice-sack stock sign in five languages: the real Intl.PluralRules picks one, few, many or other for your number, including "1.0" and the 22nd in the queue…
Why it matters
Once your app is multilingual, plurals become a trap: Polish needs 4 forms, Arabic 6, Indonesian 1. English rules written into the code make sentences ungrammatical. PluralRules gives the right category, the base of every i18n library.
The key idea
"Add -s for the plural" is right in only a few languages
Common mistakes
Plural text in a multilingual app is ungrammatical once translatedn === 1 ? a : b is only right for two-form languages. Polish needs 4, Arabic 6. Use PluralRules.select() and one sentence per category.
Raw categories like "few" or "many" show up to users PluralRules gives a category, not a ready sentence. Supply a sentence per category: pesan[pr.select(n)].
"1st/2nd/3rd" comes out with the wrong ending The default is cardinal (1 item). For order use { type: 'ordinal' }: its categories differ again (one, two, few, other in English).
Try it in this playground
Set n = 1 English, Polish, Russian: one. Indonesian stays other, Arabic one with its own sentence.
Set n = 2 English other, Polish few, Arabic two: a category just for two.
Try 5, then 21, then 22 21 is one in Russian, many in Polish; 22 is few in both. The last digits decide, by each language’s rules.
Switch to type: 'ordinal' The queue appears: 1st, 2nd, 3rd, 4th, 11th, 21st.