Plurals with Intl.PluralRules
{
"cart": {
"items": {
"plural": "total",
"forms": {
"=0": "Tu cesta está vacía",
"one": "{count} elemento en tu cesta",
"other": "{count} elementos en tu cesta"
}
}
}
}
plural
names the numeric argument. An exact match such as
=0
is looked up first, then the category of
Intl.PluralRules
and finally
other. The number must be finite.
The runtime passes
count
to the forms as an alias of that number. When the selector is called
total, passing
{ total: 3 }
is enough. If the selector is called
count, that same argument is still required.
Alternatives with select
{
"invitation": {
"select": "role",
"forms": {
"owner": "{name}, puedes administrar el proyecto.",
"other": "{name}, puedes consultar el proyecto."
}
}
}
// In your component:
t('invitation', { role: 'owner', name: 'Meeko' })
The selector is converted to text to look up its form; a value without its own alternative uses
other. The parameters used by any of its forms are part of the required contract.
Categories of each language
Languages may need different categories. Arabic uses zero, one, two, few, many and other; the playground catalog includes those forms. Every plural or select structure requires
other. The forms contain text.