Hello,
This works as expected for the English language:
{
"photos": "one photo",
"photos_plural": "{{count}} photos"
}
But I would like to also add a phrase when count is 0 like this
{
"photos_0": "No photos",
"photos": "one photo",
"photos_plural": "{{count}} photos"
}
Above doesn't work because I read somewhere else you said it depends on the language rules. So for Russian above will work but this isn't possible for English. Is there a way to over ride this with something custom? At the moment to deal with this I am using if-else block to check if count is 0 so I can use the translation when count is 0.
Yes. English has no extra form for zero - that's why you can't define photos_0 for english.
But there is a plugin to help with this: https://github.com/i18next/i18next-intervalPlural-postProcessor
Just define in the interval the extra form for zero - all others not getting handled by an interval will automatically fallback to regular plural forms.
Thank you
If you like this module don鈥檛 forget to star this repo. Make a tweet, share the word or have a look at our https://locize.com to support the devs of this project -> there are many ways to help this project :pray:
We can use Context for this purpose. Example:
{
"photos_0": "no photo",
"photos": "one photo",
"photos_plural": "{{count}} photos"
}
const count = 0;
i18next.t('photos', {count: count, context: `${count}`})
We can't we add _zero? It should be a super common case, and we can skip adding , context:${count}``
{
"photos_zero": "no photos",
"photos": "one photo",
"photos_plural": "{{count}} photos"
}
const count = 0;
i18next.t('photos', { count: count })
Straight from RubyOnRails ;) https://guides.rubyonrails.org/i18n.html#pluralization
@kg-currenxie photos_zero is something you like to express -> but by definition it is not a pluralform
so there is the context option or https://github.com/i18next/i18next-intervalPlural-postProcessor/ to express more custom ranges
yes, i didn't say its a plural form
by definition, its "nothing", and i see it independent from language grammar
its a logical one imo :)
the other plural forms, like arabic can still use the _0 formats
@kg-currenxie other languages like arabic have an extra form for zero https://unicode-org.github.io/cldr-staging/charts/37/supplemental/language_plural_rules.html#ar
Most helpful comment
We can use Context for this purpose. Example: