← All recipes
Moderne licensed

React i18next internationalization

Recipe IDorg.openrewrite.codemods.ReactI18Next
Artifactorg.openrewrite.recipe:rewrite-codemods

Automatically 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.

Single recipeMSAL

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.2

Options

NameTypeDescription
translationFilePathStringPath 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
importNamerequiredStringThe package name to import translation functions from. Required.
e.g. react-i18next
translationRootStringRoot key in the translation file to organize translations under. Defaults to common.
e.g. common
filePatternStringGlob pattern to specify which files to transform. Defaults to all files.
e.g. src/**/*.tsx
parserStringParser 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