Use an i18n library (react-intl/FormatJS, i18next with react-i18next, or Lingui) that keeps translations in message catalogs keyed by id, exposes them through a provider + hook/component, and formats with ICU MessageFormat (plurals, select, interpolation). Use the built-in Intl APIs for dates, numbers, currencies, relative time and lists. Load only the active locale's messages (code splitting), detect the locale from the URL, user settings or Accept-Language, set <html lang dir>, support RTL with logical CSS properties, and render the same locale on server and client to avoid hydration mismatches.
// messages/en.json
{ "cart.items": "{count, plural, =0 {Your cart is empty} one {# item} other {# items}}" }
// messages/fr.json
{ "cart.items": "{count, plural, =0 {Votre panier est vide} one {# article} other {# articles}}" }
import { IntlProvider, FormattedMessage, useIntl } from 'react-intl';
function App({ locale, messages }) {
return (
<IntlProvider locale={locale} messages={messages} defaultLocale="en">
<CartSummary count={3} total={4999} />
</IntlProvider>
);
}
function CartSummary({ count, total }) {
const intl = useIntl();
return (
<p>
<FormattedMessage id="cart.items" values={{ count }} />
{' · '}
{intl.formatNumber(total / 100, { style: 'currency', currency: 'EUR' })}
</p>
);
}
"You have " + n + " items" can't be translated correctly: word order and plural rules differ (Arabic has six plural forms, Japanese has none). Use full ICU messages.Intl (Intl.DateTimeFormat, NumberFormat, RelativeTimeFormat, PluralRules, ListFormat, DisplayNames) rather than hand-rolled formatting or heavy libraries. Format in the user's time zone deliberately.import(\./messages/${locale}.json`)` keeps the bundle small. With Server Components, translate on the server and send only rendered text, so no catalog ships to the client for server-only parts./fr/products) is good for SEO (hreflang), shareable links and caching. Persist the user's choice and fall back to Accept-Language.dir="rtl" and use logical properties (margin-inline-start, inset-inline-end) so layouts mirror automatically. Flip directional icons.<b>…</b> in messages mapped to components), not dangerouslySetInnerHTML.const label = t('x') outside a component) never updates on a locale change.lang on <html>, which screen readers need for pronunciation.Intl.Collator.Intl, and why concatenation fails.lang/dir attributes.Spotted a mistake or a rights concern? Report an issue