Returns a list of possible pluralization keys.
This is defined by a chain of pluralizers, going from locale set
explicitly, then the locale set through i18n.locale
, defaulting to
defaultPluralizer
.
The pluralizer function.
The locale.
Register a new pluralizer strategy.
You may want to support different pluralization rules based on the locales you have to support. If you do, make sure you submit a pull request at https://github.com/fnando/i18n so we can distribute it. For now only Russian is distributed.
The pluralizer will receive the I18n
instance, together with count
.
Is up to the pluralizer to return a list of possible keys given that count.
The Russian pluralizer, for instance, returns one
, few
, many
, other
as possible pluralization keys.
You can view a complete list of pluralization rules at unicode.org.
You can also leverage
make-plural, rather than writing
all your pluralization functions. For this, you must wrap make-plural's
function by using useMakePlural({ pluralizer, includeZero, ordinal })
:
import { ru } from "make-plural";
import { useMakePlural } from "i18n-js";
i18n.pluralization.register("ru", useMakePlural({ pluralizer: ru }));
The locale.
The pluralizer function.
Generated using TypeDoc
This class enables registering different strategies for pluralization, as well as getting a pluralized translation.
The default pluralization strategy is based on three counters:
one
: returned when count is equal to absolute1
.zero
: returned when count is equal to0
. If this translation is not set, then it defaults toother
.other
: returned when count is different than absolute1
.When calling
i18n.translate
(or its alias), pluralization rules will be triggered whenever the translation options containcount
.Example
A JSON describing the pluralization rules.
Example
How to get pluralized translations.