Sub topic 1
What Internationalisation Involves and What Breaks Without It
Prerequisites
Assume you can write React function components, use hooks, import npm packages, and read basic TypeScript. You should also know that a locale describes language and regional conventions.
Internationalisation, often written i18n, prepares software to support different languages and regions. Localisation, or l10n, supplies the language-specific translations, formats, and cultural choices.
Hard-coded text and formats make localisation difficult:
"Hello, " + nameprevents translators from changing word order.12/2/2026is ambiguous. It can mean December 2 or February 12.$1,234.50is unsuitable for every currency or region.- A layout built only with left and right properties can fail in right-to-left languages.
A useful design separates application data from its presentation:
flowchart TD
A[Application data] --> B[Locale-aware messages and formatters]
B --> C[Rendered React UI]
D[Locale: en-US or de-DE] --> BLocales and Language Tags
A locale identifies language and optional regional conventions. BCP 47 language tags use subtags such as en, en-US, or de-DE.
Use the most specific locale your application supports, then define a fallback. For example, en-GB can fall back to en, and unsupported languages can fall back to en-US.
Message Catalogs and Translation Keys
A message catalog maps stable translation keys to messages. Keys should describe meaning rather than the original English wording:
| Key | English message |
|---|---|
| `cart.items` | `{{count}} items in your cart` |
The catalog keeps translations outside components. Variables such as count are inserted by the translation system, allowing translators to reorder them.
Setting Up react-i18next
react-i18next connects React components to i18next, a translation library. Install i18next, react-i18next, and their type packages if your project requires them.
// i18n.ts
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
i18n.use(initReactI18next).init({
resources: {
en: { translation: { "cart.items": "{{count}} items in your cart" } },
de: { translation: { "cart.items": "{{count}} Artikel in Ihrem Warenkorb" } },
},
lng: "en",
fallbackLng: "en",
interpolation: { escapeValue: false },
});
export default i18n;Import this module once during application startup. Components can then call useTranslation() and translate keys without knowing where the catalog is stored.
Exercise
Why should a component translate cart.items instead of concatenating a number with English text?
Show answer
The catalog can choose the correct word order, grammar, and plural form for each locale.