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
babel-plugin extractor i18n i18next internationalization react react-i18next static-analysis

Logo

babel-plugin-i18next-extract

License: MIT CI Netlify Status Test Coverage

NPM


babel-plugin-i18next-extract is a Babel Plugin that will traverse your Javascript/Typescript code in order to find i18next translation keys.

Features

Documentation

You can check out the full documentation at i18next-extract.netlify.app.

Quick Start

Installation

yarn add --dev babel-plugin-i18next-extract

# or

npm i --save-dev babel-plugin-i18next-extract

Minimal configuration

If you don't have a babel configuration yet, you can follow the Configure Babel documentation page to get started.

Declare the plugin like any other plugin in your .babelrc and you're good to go:

{
  "plugins": [
    "i18next-extract",
    // […] your other plugins […]
  ]
}

You may want to specify additional configuration options:

{
  "plugins": [
    ["i18next-extract", {"nsSeparator": "~"}],
    // […] your other plugins […]
  ]
}

For an exhaustive list of configuration options, check out the Configuration page.

Once the plugin is setup, you can build your app normally or run Babel through Babel CLI:

yarn run babel -f .babelrc 'src/**/*.{js,jsx,ts,tsx}'

# or

npm run babel -f .babelrc 'src/**/*.{js,jsx,ts,tsx}'

Extracted translations land in the extractedTranslations/ directory by default.