gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
159 stars 37 forks source link

Adding count to t options throws error at computeDerivedKeys and causes webpack build to fail #256

Closed benfosterlitmos closed 10 months ago

benfosterlitmos commented 11 months ago

Describe the bug

Webpack build is failing when specifying the count property in a t call. If I remove count then the strings get extracted correctly. When using webpack devserver+HMR webpack gets stuck in an infinite error loop.

The language code shown in the error message is not always en-US, the other common code I see is my but it's not consistent.

Error: /Users/....../MyComponent.js: Unknown locale 'en-US'. at computeDerivedKeys (/Users/....../node_modules/babel-plugin-i18next-extract/index.js:1798:32) at /Users/....../node_modules/babel-plugin-i18next-extract/index.js:1970:103 at Array.reduce () at PluginPass.post (/Users/....../node_modules/babel-plugin-i18next-extract/index.js:1970:56) at transformFile (/Users/....../node_modules/@babel/core/lib/transformation/index.js:85:27) at transformFile.next () at run (/Users/....../node_modules/@babel/core/lib/transformation/index.js:24:12) at run.next () at transform (/Users/....../node_modules/@babel/core/lib/transform.js:22:41) at transform.next () at step (/Users/....../node_modules/gensync/index.js:261:32) at /Users/....../node_modules/gensync/index.js:273:13 at async.call.result.err.err (/Users/....../node_modules/gensync/index.js:223:11)

How to reproduce

Error occurs when I add a count property to the t options.

Babel configuration:

[
    "i18next-extract",
    {
        locales: [
    "en",
    "en-US",
    "en-GB",
    "ar",
    "zh-CN",
    "zh-HK",
    "cs-CZ",
    "cy",
    "da",
    "nl",
    "fi",
    "fil",
    "fr-CA",
    "fr-FR",
    "de",
    "he",
    "hi",
    "hu",
    "id",
    "it",
    "ja",
    "ko",
    "no",
    "pl",
    "pt",
    "pt-BR",
    "ro",
    "ru",
    "sk",
    "es-MX",
    "es",
    "sv",
    "te",
    "tr",
    "vi",
    "my",
    "th",
    "sw"
],
        useI18nextDefaultValue: true,
        useI18nextDefaultValueForDerivedKeys: true,
        enableExperimentalIcu: true,
        compatibilityJSON: "v4",
        jsonSpace: 2,
        outputPath: "locale/{{locale}}/{{ns}}.json"
    }
]

Reproduction:

t("mykey", {
      defaultValue: `{{count}} users`
      count: count
  })

Your environment

I'm note sure if there is something I'm missing in terms of extra modules or configuration required for plurals to work?

yoroshikun commented 10 months ago

I get the same~ not sure either ;-;