React › Internationalization (i18n) in React
How does the react i18next library help manage translations in a React app?
IntermediateAnswer
react i18next lets you organize translated text into separate files for each language, and provides a useTranslation hook that gives your components a simple function to look up the correct translated text based on the currently selected language, including support for things like pluralization and inserting dynamic values.
import { useTranslation } from 'react-i18next';
function Greeting({ name }) {
const { t } = useTranslation();
return <p>{t('greeting', { name })}</p>;
}
// translation file: { "greeting": "Hello, {{name}}" }Real-world example A travel booking app displays a personalized greeting with the traveler's name inserted correctly into the sentence, using react i18next to combine a translated template with dynamic user data.