React i18next internationalization
Recipe ID
org.openrewrite.codemods.ReactI18NextArtifact
org.openrewrite.recipe:rewrite-codemodsAutomatically internationalizes React applications by extracting hardcoded strings and replacing them with react-i18next translation calls. Handles JSX text, attributes, and template literals with variables. Creates and updates a translation JSON file with extracted strings.
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.codemods.ReactI18Next --recipe-option "importName=react-i18next"If the recipe isn’t available locally, install it with:
mod config recipes jar install org.openrewrite.recipe:rewrite-codemods:0.27.2Options
| Name | Type | Description |
|---|---|---|
translationFilePath | String | Path to the translation JSON file where extracted strings will be stored. Defaults to translations.json in the root of the project.e.g. ./src/locales/en.json |
importNamerequired | String | The package name to import translation functions from. Required. e.g. react-i18next |
translationRoot | String | Root key in the translation file to organize translations under. Defaults to common.e.g. common |
filePattern | String | Glob pattern to specify which files to transform. Defaults to all files. e.g. src/**/*.tsx |
parser | String | Parser to use for transforming files. Defaults to auto-detection based on file extensions (tsx/ts/babel).e.g. tsx |
Data tables
Structured output this recipe can produce.
- Source files that had resultsSource files that were modified by the recipe run.
org.openrewrite.table.SourcesFileResults - Source files that had search resultsSearch results that were found during the recipe run.
org.openrewrite.table.SearchResults - Source files that errored on a recipeThe details of all errors produced by a recipe run.
org.openrewrite.table.SourcesFileErrors - Recipe performanceStatistics used in analyzing the performance of recipes.
org.openrewrite.table.RecipeRunStats