Plurals
Plural can be combined with interpolation, context, ...
These plurals are streamlines 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

Singular / Plural

keys
1
{
2
"key_one": "item",
3
"key_other": "items",
4
"keyWithCount_one": "{{count}} item",
5
"keyWithCount_other": "{{count}} items"
6
}
Copied!
sample
1
i18next.t('key', {count: 0}); // -> "items"
2
i18next.t('key', {count: 1}); // -> "item"
3
i18next.t('key', {count: 5}); // -> "items"
4
i18next.t('key', {count: 100}); // -> "items"
5
i18next.t('keyWithCount', {count: 0}); // -> "0 items"
6
i18next.t('keyWithCount', {count: 1}); // -> "1 item"
7
i18next.t('keyWithCount', {count: 5}); // -> "5 items"
8
i18next.t('keyWithCount', {count: 100}); // -> "100 items"
Copied!
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
1
{
2
"key_zero": "zero",
3
"key_one": "singular",
4
"key_two": "two",
5
"key_few": "few",
6
"key_many": "many",
7
"key_other": "other"
8
}
Copied!
sample
1
i18next.t('key', {count: 0}); // -> "zero"
2
i18next.t('key', {count: 1}); // -> "singular"
3
i18next.t('key', {count: 2}); // -> "two"
4
i18next.t('key', {count: 3}); // -> "few"
5
i18next.t('key', {count: 4}); // -> "few"
6
i18next.t('key', {count: 5}); // -> "few"
7
i18next.t('key', {count: 11}); // -> "many"
8
i18next.t('key', {count: 99}); // -> "many"
9
i18next.t('key', {count: 100}); // -> "other"
Copied!

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).
keys
1
// i.e. italian
2
{
3
"key_one": "singular", // cardinal form
4
"key_other": "other", // cardinal form
5
"key_many": "many" // ordinal form
6
}
Copied!
sample
1
i18next.t('key', {count: 0}); // -> "other"
2
i18next.t('key', {count: 1}); // -> "singular"
3
i18next.t('key', {count: 2}); // -> "other"
4
i18next.t('key', {count: 11}); // -> "other"
5
i18next.t('key', {count: 11, ordinal: true}); // -> "many"
Copied!

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
1
import i18next from 'i18next';
2
import intervalPlural from 'i18next-intervalplural-postprocessor';
3
4
i18next
5
.use(intervalPlural)
6
.init(i18nextOptions);
Copied!
keys
1
{
2
"key1_one": "{{count}} item",
3
"key1_other": "{{count}} items",
4
"key1_interval": "(1)[one item];(2-7)[a few items];(7-inf)[a lot of items];",
5
"key2_one": "{{count}} item",
6
"key2_other": "{{count}} items",
7
"key2_interval": "(1)[one item];(2-7)[a few items];"
8
}
Copied!
sample
1
i18next.t('key1_interval', {postProcess: 'interval', count: 1}); // -> "one item"
2
i18next.t('key1_interval', {postProcess: 'interval', count: 4}); // -> "a few items"
3
i18next.t('key1_interval', {postProcess: 'interval', count: 100}); // -> "a lot of items"
4
5
// not matching into a range it will fallback to
6
// the regular plural form
7
i18next.t('key2_interval', {postProcess: 'interval', count: 1}); // -> "one item"
8
i18next.t('key2_interval', {postProcess: 'interval', count: 4}); // -> "a few items"
9
i18next.t('key2_interval', {postProcess: 'interval', count: 100}); // -> "100 items"
Copied!
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.:
1
"key2_interval": "(1){one item};(2-7){a few items};"
Copied!
Last modified 1mo ago