Plural can be combined with interpolation, context, ...
These plurals are streamlined with the one used in the .
You need totheAPI.
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
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.
You can use this small utility to get the correct plural suffixes.
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.
Want to define phrases expressing the number of items lies in a range. Like a few items or a lot of items.
import i18next from 'i18next';
import intervalPlural from 'i18next-intervalplural-postprocessor';
i18next
.use(intervalPlural)
.init(i18nextOptions);
keys
{
"key1_one": "{{count}} item",
"key1_other": "{{count}} items",
"key1_interval": "(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];",
"key2_one": "{{count}} item",
"key2_other": "{{count}} items",
"key2_interval": "(1)[one item];(2-7)[a few items];"
}
sample
i18next.t('key1_interval', {postProcess: 'interval', count: 1}); // -> "one item"
i18next.t('key1_interval', {postProcess: 'interval', count: 4}); // -> "a few items"
i18next.t('key1_interval', {postProcess: 'interval', count: 100}); // -> "a lot of items"
// not matching into a range it will fallback to
// the regular plural form
i18next.t('key2_interval', {postProcess: 'interval', count: 1}); // -> "one item"
i18next.t('key2_interval', {postProcess: 'interval', count: 4}); // -> "a few items"
i18next.t('key2_interval', {postProcess: 'interval', count: 100}); // -> "100 items"
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.:
"key2_interval": "(1){one item};(2-7){a few items};"
With a new was introduced that changed the suffixes.
To convert your existing translations to the new v4 format, have a look at or .
Or try, 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