Internationalization (i18n) in React 19

Internationalization enables your app to support multiple languages and regions. React 19 projects typically use react-intl or i18next for i18n.

Setup

  • Install react-intl: npm install react-intl or i18next: npm install react-i18next i18next
  • Configure provider in your app root:
    import { IntlProvider } from 'react-intl';
    <IntlProvider locale="en" messages={messages['en']}>
    <App />
    </IntlProvider>

Best Practices

  • Store messages in separate JSON files per language (e.g., locales/en.json, locales/fr.json).
  • Use short, descriptive keys for messages.
  • Avoid hardcoding text in components; use translation functions/components.
  • Provide fallback languages for missing translations.

Locale Detection

  • Detect user locale from browser settings or user profile.
  • Allow users to switch languages via UI controls.

Example: Using Translations in Components

import { FormattedMessage } from 'react-intl';
<FormattedMessage id="welcome" defaultMessage="Welcome" />

Fallback Strategies

  • Set default locale and fallback messages in provider config.
  • Log missing translations for review.

References