gilbsgilbs/babel-plugin-i18next-extract

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

benfosterlitmos opened this issue · 1 comments

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

  • OS: MacOS 13
  • Plugin version: 0.9.0
  • Babel version: 7.21.4
  • Webpack version: 5.27.0
  • Node version: 18.15.0

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

I get the same~ not sure either ;-;