i18next / i18next-gitbook

165 stars 172 forks source link

Need help to "Plurals" for muti-language support #141

Closed yanweibj closed 4 years ago

yanweibj commented 4 years ago

https://www.i18next.com/translation-function/plurals

We have a project that support muti-languages. And we use { "keyWithCount": "{{count}} item", "keyWithCount_plural": "{{count}} items" }

It works well for en/fr/de. count = 1 return "key" count = 2,3,4... return "key_plural" image

But for ja/ko/zh-cn/zh-tw. the code will return "key_0" no matter the count is. image

My code is like this: rules: {{count}} rule rules_pural: {{count}} rules

For ja/ko/zh-cn/zh-tw, It will use "rules: {{count}} rule" as it can't find key "rules_0".

Please help to advise how to solve my problem.

yanweibj commented 4 years ago

My project will use the same keys in all languages.

adrai commented 4 years ago

For these languages there is no singular/plural distinction. There's only 1 key "rules_0" This is how the plural rules work in i18next. So you need to add the key "rules_0" for zh for example and no rules + rules_plural

jamuhl commented 4 years ago

https://www.i18next.com/translation-function/plurals#languages-with-multiple-plurals same rule for languages not having pluralforms

yanweibj commented 4 years ago

Thank you all.