Using the useTranslation Hook
Replace hardcoded strings with t() calls and organise translation JSON files.
Welcome
In this lesson you will use the useTranslation hook to access the t() function, translate strings in components, and organise translation JSON files by namespace.
The useTranslation Hook
Call useTranslation() inside a component to get the `t` translation function and the `i18n` instance. Pass the namespace name if using namespaced translations.
import { useTranslation } from 'react-i18next';
function Header() {
const { t } = useTranslation('common');
return <h1>{t('app_title')}</h1>;
}All lessons in this course
- Setting Up react-i18next
- Using the useTranslation Hook
- Pluralisation & Interpolation
- Language Switcher & Lazy-Loading Translations