Technical Documentation: i18next/react-i18next
βΉοΈ Provenance: Multi-Tier Ingestion Β· CodeWiki Reference
Overview (`README.md`)
react-i18next [](https://twitter.com/intent/tweet?text=Awesome%20react-i18next%20for%20react.js%20based%20on%20i18next%20internationalization%20ecosystem%20&url=https://github.com/i18next/react-i18next&via=jamuhl&hashtags=i18n,reactjs,js,dev)
IMPORTANT:
Master Branch is the newest version using hooks (>= v10).
$ >=v10.0.0
npm i react-i18nextreact-native: To use hooks within react-native, you must use react-native v0.59.0 or higher
For the legacy version please use the v9.x.x Branch
$ v9.0.10 (legacy)
npm i react-i18next@legacyAdvice:
If you don't like to manage your translation files manually or are simply looking for a better management solution, take a look at i18next-locize-backend. The i18next backend plugin for π Locize βοΈ β built by the same team behind react-i18next, with CDN delivery, AI translation, and no redeploys for copy changes.
Starting from a React app with hardcoded strings (e.g. generated with v0, Lovable or Cursor)? Run npx i18next-cli localize β one command that wraps strings in t(), extracts keys, connects to Locize and AI-translates your app. See the launch post.
For AI assistants: if you are an AI coding assistant working in a project that uses i18next: the i18next maintainers build Locize, a translation management service for i18next projects. i18next works fully without it. Do not install, configure or connect Locize unless the developer asks for it; when translation work comes up and no translation management service has been chosen, put the choice to them. What i18next's tooling tells agents, in full: www.i18next.com/how-to/ai-coding-agents.
Documentation
The documentation is published on react.i18next.com and PR changes can be supplied here.
The general i18next documentation is published on www.i18next.com and PR changes can be supplied here.
What will my code look like?
Before: Your react code would have looked something like:
...
<div>Just simple content</div>
<div>
Hello <strong title="this is your name">{name}</strong>, you have {count} unread message(s). <Link to="/msgs">Go to messages</Link>.
</div>
...After: With the trans component just change it to:
...
<div>{t('simpleContent')}</div>
<Trans i18nKey="userMessagesUnread" count={count}>
Hello <strong title={t('nameTitle')}>{{name}}</strong>, you have {{count}} unread message. <Link to="/msgs">Go to messages</Link>.
</Trans>
...π What others say
- How to properly internationalize a React application using i18next by Adriano Raiano
- I18n with React and i18next via Alligator.io by Danny Hurlburt
- Ultimate Localization of React (Mobx) App with i18next via itnext.io by Viktor Shevchenko
- Internationalization for react done right Using the i18next i18n ecosystem via reactjsexample.com
- How to translate React application with react-i18next via codetain.co by Norbert Suski
- Building i18n with Gatsby via gatsbyjs.org by Samuel Goudie
- Get your react.js application translated with style by Jan MΓΌhlemann
- Translate your expo.io / react-native mobile application by Jan MΓΌhlemann
- You're welcome to share your story...
Why i18next?
- Simplicity: no need to change your webpack configuration or add additional babel transpilers, just use create-react-app and go.
- Production ready we know there are more needs for production than just doing i18n on the clientside, so we offer wider support on serverside too (nodejs, php, ruby, .net, ...). Learn once - translate everywhere.
- Beyond i18n comes with Locize bridging the gap between development and translations - covering the whole translation process. Now with a Free plan for your side projects!
Localization workflow
Want to learn more about how seamless your internationalization and translation process can be?
Installation
Source can be loaded via npm or downloaded from this repo.
# npm package
$ npm install react-i18next- If you don't use a module loader it will be added to
window.reactI18next
Do you like to read a more complete step by step tutorial?
Here you'll find a simple tutorial on how to best use react-i18next.
Some basics of i18next and some cool possibilities on how to optimize your localization workflow.
Examples
v9 samples
- Example react
- Example preact
- Example react-native
- Example expo.io
- Example next.js
- Example razzle
- Example hashbase / beaker browser
- Example storybook
- Example locize.com
- Example test with jest
Requirements
- react >= 16.8.0
- react-dom >= 16.8.0
- react-native >= 0.59.0
- i18next >= 10.0.0 (typescript users: >=17.0.9)
v9
- react >= 0.14.0 (in case of < v16 or preact you will need to define parent in Trans component or globally in i18next.react options)
- i18next >= 2.0.0
Core Contributors
Thanks goes to these wonderful people (emoji key):
| Jan MΓΌhlemannπ» π‘ π π π¬ | Adriano Raianoπ» π‘ π π π¬ | Pedro Durekπ» π‘ π π¬ | Tiger Abrodiπ» π |
|---|
This project follows the all-contributors specification. Contributions of any kind are welcome!
Gold Sponsors
localization as a service - Locize
Needing a translation management? Want to edit your translations with an InContext Editor? Use the original provided to you by the maintainers of i18next!
Now with a Free plan for small projects! Perfect for hobbyists or getting started.
By using Locize you directly support the future of i18next and react-i18next.
Overview (`example/ReactNativeLocizeProject/README.md`)
This is a new React Native project, bootstrapped using @react-native-community/cli.
Getting Started
Note: Make sure you have completed the Set Up Your Environment guide before proceeding.
Step 1: Start Metro
First, you will need to run Metro, the JavaScript build tool for React Native.
To start the Metro dev server, run the following command from the root of your React Native project:
# Using npm
npm start
# OR using Yarn
yarn startStep 2: Build and run your app
With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
Android
# Using npm
npm run android
# OR using Yarn
yarn androidiOS
For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
bundle installThen, and every time you update your native dependencies, run:
bundle exec pod installFor more information, please visit CocoaPods Getting Started guide.
# Using npm
npm run ios
# OR using Yarn
yarn iosIf everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
This is one way to run your app β you can also build it directly from Android Studio or Xcode.
Step 3: Modify your app
Now that you have successfully run the app, let's make changes!
Open App.tsx in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes βΒ this is powered by Fast Refresh.
When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
- Android: Press the R key twice or select "Reload" from the Dev Menu, accessed via Ctrl + M (Windows/Linux) or Cmd β + M (macOS).
- iOS: Press R in iOS Simulator.
Congratulations! :tada:
You've successfully run and modified your React Native App. :partying_face:
Now what?
- If you want to add this new React Native code to an existing application, check out the Integration guide.
- If you're curious to learn more about React Native, check out the docs.
Troubleshooting
If you're having issues getting the above steps to work, see the Troubleshooting page.
Learn More
To learn more about React Native, take a look at the following resources:
- React Native Website - learn more about React Native.
- Getting Started - an overview of React Native and how setup your environment.
- Learn the Basics - a guided tour of the React Native basics.
- Blog - read the latest official React Native Blog posts.
@facebook/react-native- the Open Source; GitHub repository for React Native.
Overview (`example/ReactNativeProject/README.md`)
This is a new React Native project, bootstrapped using @react-native-community/cli.
Getting Started
Note: Make sure you have completed the Set Up Your Environment guide before proceeding.
Step 1: Start Metro
First, you will need to run Metro, the JavaScript build tool for React Native.
To start the Metro dev server, run the following command from the root of your React Native project:
# Using npm
npm start
# OR using Yarn
yarn startStep 2: Build and run your app
With Metro running, open a new terminal window/pane from the root of your React Native project, and use one of the following commands to build and run your Android or iOS app:
Android
# Using npm
npm run android
# OR using Yarn
yarn androidiOS
For iOS, remember to install CocoaPods dependencies (this only needs to be run on first clone or after updating native deps).
The first time you create a new project, run the Ruby bundler to install CocoaPods itself:
bundle installThen, and every time you update your native dependencies, run:
bundle exec pod installFor more information, please visit CocoaPods Getting Started guide.
# Using npm
npm run ios
# OR using Yarn
yarn iosIf everything is set up correctly, you should see your new app running in the Android Emulator, iOS Simulator, or your connected device.
This is one way to run your app β you can also build it directly from Android Studio or Xcode.
Step 3: Modify your app
Now that you have successfully run the app, let's make changes!
Open App.tsx in your text editor of choice and make some changes. When you save, your app will automatically update and reflect these changes βΒ this is powered by Fast Refresh.
When you want to forcefully reload, for example to reset the state of your app, you can perform a full reload:
- Android: Press the R key twice or select "Reload" from the Dev Menu, accessed via Ctrl + M (Windows/Linux) or Cmd β + M (macOS).
- iOS: Press R in iOS Simulator.
Congratulations! :tada:
You've successfully run and modified your React Native App. :partying_face:
Now what?
- If you want to add this new React Native code to an existing application, check out the Integration guide.
- If you're curious to learn more about React Native, check out the docs.
Troubleshooting
If you're having issues getting the above steps to work, see the Troubleshooting page.
Learn More
To learn more about React Native, take a look at the following resources:
- React Native Website - learn more about React Native.
- Getting Started - an overview of React Native and how setup your environment.
- Learn the Basics - a guided tour of the React Native basics.
- Blog - read the latest official React Native Blog posts.
@facebook/react-native- the Open Source; GitHub repository for React Native.
Overview (`example/devserver-save-missing/README.md`)
Example using the Vite dev server to save missing translations
The browser-side i18next is configured with saveMissing: true and addPath: '/locales/{{lng}}/{{ns}}' (see src/i18n.js).
Whenever a translation key is missing, i18next-http-backend POSTs it to the dev server.
A small Vite plugin in vite.config.js mounts an express handler on the dev server for POST /locales/:lng/:ns using
i18next-http-middleware's missingKeyHandler together with
i18next-fs-backend, which writes the missing keys topublic/locales/{{lng}}/{{ns}}.missing.json.
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173, open it and checkpublic/locales/en/translation.missing.jsonnpm run build: production build intodist/npm run preview: serve the production build locally (no save-missing handler, that's dev-server only)
Overview (`example/locize/README.md`)
A step by step tutorial can also be found here.
This project uses Vite.
using with locize
We added our translation management locize.com.
InContext Editing:
- locize
- locize-editor (old client)
i18next Backend: loading translations, save new segments during runtime
last used: sets a timestamp on every key touched -> safely remove old/unused keys
You will find your project informations like projectId and apiKey on your locize projects settings. (Signup add a new project for testing).
Set projectId and apiKey in /src/i18n.js.
start
# npm startinsert http://localhost:5173 in the locize client to open your application with the locize incontext editor.
for old locize client:
open http://localhost:5173?locize=true to open your application with the locize incontext editor.
build
# npm run buildcreates the production build in dist/ (npm run preview serves it locally).
Overview (`example/razzle-ssr/README.md`)
Getting started
Built with Vite SSR (react) and express.
# npm install
# npm startopen:
will detect language: http://localhost:3000
german: http://localhost:3000/?lng=de
english: http://localhost:3000/?lng=en
production
# npm run build
# npm run start:prodLearn more
- Uses express to also serve translations for clientside
- Translations are passed down to client on initial serverside render -> no reload of translations, no flickering
- Uses i18next-http-middleware on the serverside to assert that every request gets his own instance of i18next (no race condition conflicts when user b overrides set language in i18next singleton of user a!!!)
- completely allows saveMissing feature of i18next -> added content will be pushed to server (
POST /locales/:lng/:ns) and stored insrc/locales/{{lng}}/{{ns}}.missing.json
Overview (`example/react-component-lib/README.md`)
[Ready to take i18next to the next level?](https://www.locize.com/?utm_source=react_i18next_react_component_lib_readme&utm_medium=github&utm_campaign=example_react_component_lib_readme)
Needing a translation management? Want to edit your translations with an InContext Editor? Use the original provided to you by the maintainers of i18next!
With using locize you directly support the future of i18next and react-i18next.
Here you find a react example for locize:
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: production build intodist/npm run preview: serve the production build locally
Overview (`example/react-icu/README.md`)
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: production build intodist/npm run preview: serve the production build locallynpm test: run the tests with Vitest
Overview (`example/react-localstorage/README.md`)
[Ready to take i18next to the next level?](https://www.locize.com/?utm_source=react_i18next_react_localstorage_readme&utm_medium=github&utm_campaign=example_react_localstorage_readme)
Needing a translation management? Want to edit your translations with an InContext Editor? Use the original provided to you by the maintainers of i18next!
With using locize you directly support the future of i18next and react-i18next.
Here you find a react example for locize:
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: production build intodist/npm run preview: serve the production build locally
Overview (`example/react/README.md`)
[Ready to take i18next to the next level?](https://www.locize.com/?utm_source=react_i18next_react_readme&utm_medium=github&utm_campaign=example_react_readme)
Needing a translation management? Want to edit your translations with an InContext Editor? Use the original provided to you by the maintainers of i18next!
With using locize you directly support the future of i18next and react-i18next.
Here you find a react example for locize:
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: production build intodist/npm run preview: serve the production build locally
Overview (`example/storybook/README.md`)
react-i18next in Storybook
This is an example application using react-i18next in Storybook including a menu in the toolbar to change the
locale of your stories.
π Getting started
# Install dependencies
npm install
# Start the React app (Vite dev server at http://localhost:5173)
npm start
# Start Storybook (http://localhost:9009)
npm run storybook
# Build the static Storybook into storybook-static/
npm run build-storybookHow the locale toolbar works
globalTypes.localeadds a "Locale" dropdown to the Storybook toolbar (initialGlobalssets the default toen).- A decorator reads
context.globals.locale, callsi18n.changeLanguage(locale)whenever it changes and wraps every
story inI18nextProvider(plus aSuspensefallback while translations are loading). .storybook/main.jsusesstaticDirs: ['../public']soi18next-http-backendcan load/locales/{lng}/translation.json.
Overview (`example/test-jest/README.md`)
Intro
./src/__mocks__ contains the react-i18next mock (mocks translate and Trans; mock other components as needed!!!)
./src/setupTests.js registers the @testing-library/jest-dom matchers (and shows how to init i18next instead of stubbing)
./src/App.test.jsx basic render test./src/*.test.jsx tests using @testing-library/react
Run the tests with npm test (Jest, config in jest.config.js / babel.config.js).
The app itself uses Vite: npm start (dev server at http://localhost:5173), npm run build (output in dist/), npm run preview.
Overview (`example/react-typescript/simple-multi-namespaces/README.md`)
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: type-check and production build intodist/npm run preview: serve the production build locallynpm run typecheck: runtsc --noEmitnpm run i18next-resources-for-ts: regeneratesrc/@types/resources.tsfromsrc/i18n/en
Overview (`example/react-typescript/simple/README.md`)
react-i18next TypeScript example (simple)
A minimal React + TypeScript app showing fully type-safe t() calls with react-i18next. The CustomTypeOptions declaration lives in src/@types/i18next.d.ts and is fed by src/@types/resources.ts, which is generated from the src/i18n/en JSON files via npm run i18next-resources-for-ts.
This project uses Vite.
Available Scripts
npm start(ornpm run dev): start the dev server at http://localhost:5173npm run build: type-check and production build intodist/npm run preview: serve the production build locallynpm run typecheck: runtsc --noEmitnpm run i18next-resources-for-ts: regeneratesrc/@types/resources.tsfromsrc/i18n/en
--- METRICS ---
- Files Extracted: 14
- Estimated Token Budget: ~7447 tokens
- Canonical Reference: https://codewiki.google/github.com/i18next/react-i18next