ttag-org / ttag

:orange_book: simple approach for javascript localization
https://ttag.js.org/
MIT License
338 stars 41 forks source link

Plural for a 0 value #210

Closed nico3333fr closed 3 years ago

nico3333fr commented 3 years ago

Hi there,

I'm working with a countdown in JS that uses ttag for translations, and I went across this case:

c('Countdown unit').ngettext(msgid`${seconds} second`, `${seconds} seconds`, seconds)

When the number of seconds is 1, I get the singular version, but when the value is 0, I still get the plural version: image

I went in your doc, and this is the same case in your example (0 ticks): image

Is it possible to get a singular version when the value equal to 0?

Thanks in advance!

AlexMost commented 3 years ago

Hi @nico3333fr! It depends on the active language. 0 seconds is a valid form for 0 as far as I know, because plural formula for English is simply n!=1

nico3333fr commented 3 years ago

@AlexMost but is it possible to adapt it depending of the language?

AlexMost commented 3 years ago

Yes, for sure. Depending on your case, you can use useLocale function - https://ttag.js.org/docs/library-api.html#uselocale to switch language, or setDefaultLang https://ttag.js.org/docs/library-api.html#setdefaultlang if you have other than English lang in your sources.