Quick start
Last updated
Last updated
We expect you having an existing react application - if not give (npm create vite@latest
) or similar a try.
Install both react-i18next and i18next packages:
Why do you need i18next package? i18next is the core that provides all translation functionality while react-i18next gives some extra power for using with react.
Check out this basic with a and a to load translations from.
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.
Create a new file i18n.js
beside your index.js
containing following content:
The interesting part here is by i18n.use(initReactI18next)
we pass the i18n instance to react-i18next which will make it available for all the components via the context api.
Then import that in index.js
:
Using the hook in functional components is one of the options you have.
Using higher order components is one of the most used method to extend existing components by passing additional props to them.
The render prop enables you to use the t
function inside your component.
The Trans component is the best way to translate a JSX tree in one translation. This enables you to eg. easily translate text containing a link component or formatting like <strong>
.
Prefer having code to checkout? Directly dive into our examples:
Would you like to visually check the progress state of your translations?
Also read about this and .
The t
function is the main function in i18next to translate content. Read the for all the options.
Learn more about the hook .
The t
function is the main function in i18next to translate content. Read the for all the options.
Learn more about the higher order component .
Learn more about the render prop .
Don't worry if you do not yet understand how the Trans component works in detail. Learn more about it .
Depending on your learning style, you can now read the more in-depth guide and learn how to load translations using xhr or how to change the language.
Try , it shows an overview of your translations in a nice UI. Check which keys are not yet translated.