Overview (v9)
react-i18next depends on i18next to provide the localization features. So there are two main things flowing through your render tree:
The i18next instance (short i18n)
The translation function (short t)
While we primary rely on react context to pass down i18n and t the components are built to also accept those via props, options or in case of i18n via internal context / reactI18nextModule.
Components
Component | Props | Provides | Consumes |
i18n, defaultNS | i18n, defaultNs | ||
NamespacesConsumer is a render prop | t, i18n | i18n | |
withNamespaces hoc | t, i18n | i18n | |
Trans Component is used to translate JSX nodes where just using t is insufficient | t, i18n |
This means your tree will look something like this (assuming you use the options I18nextProvider):
I18nextProvider --> NamespacesConsumer or withNamespaces HOC --> Trans or using t in your component
Getting the t function
To get the t function (providing the translation functionality) down to your component you have two options:
Using the withNamespaces hoc
Using the NamespacesConsumer render prop
Getting the i18n function into the flow
You have the following options to pass the i18next instance to the hoc, render prop and Trans component:
Use the provider
Use the reactI18nextModule
Last updated