Translation (render prop)

What it does

The Translation is a render prop and gets the t function and i18n instance to your component.

import React from 'react';
import { Translation } from 'react-i18next';

export function MyComponent() {
  return (
    <Translation>
      {
        (t, { i18n }) => <p>{t('my translated text')}</p>
      }
    </Translation>
  )
}

While you most time only need the t function to translate your content you also get the i18n instance to eg. change the language.

i18n.changeLanguage('en-US');

The Translation render prop will trigger a Suspense if not ready (eg. pending load of translation files). You can set useSuspense to false if prefer not using Suspense.

When to use?

Use the Translation render prop inside any component (class or function) to access the translation function or i18n instance.

Translation params

Loading namespaces

Overriding the i18next instance

Last updated