Getting started
Installation
Install using npm
react-i18next can be added to your project using npm:
In the /dist
folder you find specific builds for commonjs
, es6 modules
,...
The module is optimized to load by webpack, rollup, ... The correct entry points are already configured in the package.json. There should be no extra setup needed to get the best build option.
Load from CDN
You can also add a script tag to load react-i18next from one of the CDNs providing it, eg.:
unpkg.com
Translation "how to"
You should read the i18next documentation at some point as we do not repeat all the configuration options and translation functionalities like plurals, formatting, interpolation, ... here.
You have two options to translate your content:
Simple content
Simple content can easily be translated using the provided t
function.
Before:
After:
You will get the t function by using the useTranslation hook or the withTranslation hoc.
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:
Learn more about the Trans Component here
Basic sample
This basic sample tries to add i18n in a one file sample.
RESULT:
This sample while very simple does come with some drawbacks to getting the full potential from using react-i18next you should read the extended step by step guide.
Do you like to read a more complete step by step tutorial?
Last updated