i18next: Doesn't work singular/plural forms with a few counts

🐛 Bug Report

I use Trans tag. And I use nesting to create the translations string from few other. So I have to use a few different “count” for every key. I can’t use a few counts, because Trans doesn’t have such options. So I use “values”. And in this case count works fine, context works fine… but “_plural” doesn’t work.

To Reproduce

Here is code from the page:

                            <Trans
                                debug={true}
                                i18nKey="billedAfterTrial"
                                values={{
                                    currencySign: currencySign,
                                    currentPrice: currentPrice,
                                    count1: periodType.count,
                                    count2: trialType.count,
                                    count3: day,
                                    context1: periodType.context,
                                    context2: trialType.context,
                                    context3: month,
                                }}
                            >
                                [$79.99] billed [yearly] after a [7-day] trial period. Contact us via
                                support@dailyfit.io to cancel.
                            </Trans>

Here is the translation keys:

  "X period": "{{count}} week",
  "X period_plural": "{{count}} weeks",
  "X period_month": "{{count}} month",
  "X period_month_plural": "{{count}} months",
  "X period_0": "{{count}} week",
  "X period_1": "{{count}} week",
  "X period_2": "{{count}} week",
  "X period_month_0": "{{count}} month",
  "X period_month_1": "{{count}} month",
  "X period_month_2": "{{count}} month",

  "X-period": "{{count}}-week",
  "X-period_month": "{{count}}-month",

  "billedAfterTrial": "{{currencySign}}{{currentPrice}} billed every $t(X period, {\"count\": \"{{count1}}\", \"context\": \"{{ context1 }}\" }) after the $t(X-period, {\"count\": \"{{count2}}\", \"context\": \"{{ context2 }}\" }) trial period."

I changed ‘s’ in the “_0, _1, _2” (we use it for Russian), but it doesn’t work to. Also, I changed “_plural” to “_other”. And nothing works.

Expected behavior

I expect that if count1 will be 3, I’ll get “billed every 3 months”. I get “billed every 3 month”

// Paste the expected results here

Your Environment

  • i18next version: i.e. 19.9.2
  • os: Mac

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 56 (27 by maintainers)

Most upvoted comments

means (if plural):

en -> _one, _other (depending on singular or not) zh -> _other (for all)

@haoolii zh (chinese) does not differenciate singular or plural forms there is just one form so there is only the _other suffix https://en.wikipedia.org/wiki/Chinese_grammar#:~:text=Chinese nouns and other parts,"I%2C me").

Hello guys, I also have some confuse situation. my english i18n work correctly, but when i change language to zh, it always return plural key event the value is singular.

anyone can help me to solve this problem ?

https://codesandbox.io/s/react-i18next-plurals-forked-jgulw6?file=/public/locales/zh/translation.json

zh has only 1 suffix, and that’s the _other suffix: https://jsfiddle.net/6bpxsgd4 image

ahh i misunderstood, sorry… that’s because you’re still using quotes for numbers: instead of {\"count\": \"{{count2}}\" you should do {\"count\": {{count2}}

https://codesandbox.io/s/react-i18next-example-forked-vz5e8?file=/src/i18n.js:2409-2431

I see… thanks. I will try to implement it