Plurals
Plural can be combined with interpolation, context, ...
These plurals are streamlined with the one used in the Intl API. You may need to polyfill the Intl.PluralRules API, in case it is not available it will fallback to the i18next JSON format v3 plural handling.
Note: The variable name must be count
.
And it must be present: i18next.t('key', {count: 1});
There will be no fallback to the 'key'
value if count is not provided.
If you need multiple counts, take a look at nesting
We provide the ability to have special translation for {count: 0}
, so that a more natural language can be used. If the count is 0, and a _zero
entry is present, then it will be used instead of the language plural suffix.
🎓 Check out this topic in the i18next crash course video.
Singular / Plural
keys
sample
With v21.0.0 a new JSON format v4 was introduced that changed the suffixes. To convert your existing translations to the new v4 format, have a look at i18next-v4-format-converter or this web tool.
Languages with multiple plurals
Sample uses arabic which has 5 plural forms beside the singular.
keys
sample
How to find the correct plural suffix?
You can use this small utility to get the correct plural suffixes.
Or try translation-check, it shows an overview of your translations in a nice UI. It shows also the appropriate plural forms.
Or you use a smart translation management system, like locize
Ordinal plurals
There is also support for ordinal numbers (referring to the ordering or ranking of things, e.g. "1st", "2nd", "3rd" in English). The ordinal
option (and the _ordinal suffix) tells the helper to use the ordinal digit to determine the plurality key used. E.g., for "32" the ordinal digit is "2" so key_two
is used.
keys
sample
Interval plurals
Want to define phrases expressing the number of items lies in a range. Like a few items or a lot of items.
You will need to add a post processor: i18next-intervalplural-postprocessor
keys
sample
Note: The regex for the interval entry has changed in v3.0.0
of i18next-intervalPlural-postProcessor
so if you are using the older versions, you need to use the curly braces instead of the bracketes, e.g.:
Last updated