Overview (v9)
Components
import { I18nextProvider, NamespacesConsumer, Trans, withNamespaces } from 'react-i18next';
import i18n from `./i18n`; // the initialized i18next instance
export default function App () {
return (
<I18nextProvider i18n={i18n}>
<NamespacesConsumer>
{
t => <h1>{t('key')}</h1>
}
</NamespacesConsumer>
<MyComponentWithHoc />
</I18nextProvider>
)
}
function MyComponent({ t }) {
return (
<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>
)
}
const MyComponentWithHoc = withNamespaces()(MyComponent);Getting the t function
Getting the i18n function into the flow
Use the provider
Use the reactI18nextModule
Last updated