Getting started
Install react-i18next and i18next, initialize an instance, and translate your first React component with useTranslation.
Installation
Install using npm
react-i18next can be added to your project using npm:
# npm
$ npm install react-i18next i18next --saveIn the /dist folder you find specific builds for commonjs, es6 modules,...
Load from CDN
You can also add a script tag to load react-i18next from one of the CDNs providing it, eg.:
unpkg.com
Since v18 the UMD build uses the global i18next instead of bundling its own copy, so load i18next's UMD build first.
Translation "how to"
Official CLI
The official, high-performance, all-in-one command-line tool for i18next. It handles key extraction, code linting, locale syncing, and type generation. It's built with modern technologies for maximum speed and accuracy. This is the recommended tool for all i18next projects.
Not sure how many strings are still hardcoded? Run the free i18n readiness check on your public GitHub repository first.
You have two options to translate your content:
Simple content
Simple content can easily be translated using the provided t function.
Before:
After:
JSX tree
Sometimes you might want to include html formatting or components like links into your translations. (Always try to get the best result for your translators - the final string to translate should be a complete sentence).
Before: Your react code would have looked something like:
After: With the trans component just change it to:
Basic sample
This basic sample tries to add i18n in a one file sample.
RESULT:

Do you like to read a more complete step by step tutorial?
Last updated
