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

Passing count to a nested key applies to the next keys that following it #1876

Closed
marcalexiei opened this issue Dec 5, 2022 · 2 comments
Closed
Assignees

Comments

@marcalexiei
Copy link
Member

🐛 Bug Report

Using a single count inside a nested key will apply the same count to all other following nested key without their own count.

Issue occurs also with v3 json syntax.

To Reproduce

Codesandbox

import i18n from "i18next";
import LanguageDetector from "i18next-browser-languagedetector";

i18n
  .use(LanguageDetector)
  .init({
    debug: true,
    fallbackLng: "en",

    resources: {
      en: {
        translation: {
          item_one: "item",
          item_other: "items",

          thing_one: "thing",
          thing_other: "things",

          phrase: 'A: $t(thing, { "count": 2 }) B: $t(item)',
        }
      }
    },
  });

console.info(i18n.t("phrase"));

export default i18n;

Expected behaviour

At the moment both A and B got plural variant:

A: things B: items

The expected behaviour is that only A is returned with its plural variant. B uses single variant.

A: things B: item 

As a workaround you can explicit count on B:

phrase: 'A: $t(thing, { "count": 2 }) B: $t(item, { "count": 1 })',

Your Environment

  • runtime version: browser
  • i18next version: 20.0.7
  • os: Mac
@jamuhl
Copy link
Member

jamuhl commented Dec 5, 2022

not providing a count will result in resolving "other" -> so omitting the count will not result in singular but plural (other)...

@adrai adrai self-assigned this Dec 5, 2022
@adrai adrai closed this as completed in 269421c Dec 5, 2022
@adrai
Copy link
Member

adrai commented Dec 5, 2022

v22.0.8 should fix that

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

3 participants