Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to add 0 plural option for English #1220

Closed
brightpixels opened this issue Mar 17, 2019 · 8 comments
Closed

How to add 0 plural option for English #1220

brightpixels opened this issue Mar 17, 2019 · 8 comments

Comments

@brightpixels
Copy link

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.

@jamuhl
Copy link
Member

jamuhl commented Mar 17, 2019

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.

@brightpixels
Copy link
Author

Thank you

@jamuhl
Copy link
Member

jamuhl commented Mar 18, 2019

If you like this module don’t 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 🙏

@jamuhl jamuhl closed this as completed Mar 18, 2019
@AleksandrChernyavenko
Copy link

AleksandrChernyavenko commented Jul 6, 2020

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}`})

@kg-currenxie
Copy link

kg-currenxie commented Jul 9, 2020

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

@jamuhl
Copy link
Member

jamuhl commented Jul 9, 2020

@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

@kg-currenxie
Copy link

kg-currenxie commented Jul 9, 2020

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

@jamuhl
Copy link
Member

jamuhl commented Jul 9, 2020

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants