gilbsgilbs / babel-plugin-i18next-extract

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

Extract only the missing translations #173

Closed tttp closed 4 years ago

tttp commented 4 years ago

Hi,

I'm probably missing an obvious step, but how do I identify the keys that aren't already translated?

Is your feature request related to a problem? Please describe.

I'm running the extract and I get a json with all the keys existing in the project. However, some (most) already exists under the src/locales/en.json file

Describe the solution you'd like

I'd like to be able to update the en.json file and add the new keys. Ideally, with the value being set to the key by default

Describe alternatives you've considered

json diff on the keys between extractedTranslations/en/translation.json and src/locales/en.json

But it seems such an obvious workflow ("add the new translations to the existing translation json file") that I feel I'm missing something

tttp commented 4 years ago

and to answer my own question: this is the .babelrc file that does the trick:

{
  "plugins": [
    [
      "i18next-extract",
      {
        "keyAsDefaultValue": ["en"],
        "defaultNS": "common",
        "outputPath": "src/locales/{{locale}}/{{ns}}.json"
      }
    ]
  ]
}