Sub topic 1
What internationalisation involves and what breaks without it
Prerequisites
This chapter assumes you can write React function components and use hooks. You should know basic JavaScript or TypeScript, including ES modules. You should also know enough HTML and CSS to read a short stylesheet. No i18n library is needed yet.
Two terms: internationalisation and localisation
Internationalisation (often written i18n, for the 18 letters between "i" and "n") is the engineering work that lets an app support many languages and regions without code changes. Localisation (l10n) is the work of adapting the app for one specific locale. That work includes translating text and choosing local formats.
In practice, developers do i18n once and translators and product teams do l10n for each new language. If the i18n work is skipped, every new language becomes a code change.
What breaks without it
Consider a component written without i18n in mind.
export function Cart({ name, count, total }: { name: string; count: number; total: number }) {
return (
<section>
<h1>Hello, {name}!</h1>
<p>{count} item(s) in your cart</p>
<p>Total: ${total.toFixed(2)}</p>
<p>Updated {new Date().toLocaleDateString('en-US')}</p>
</section>
);
}This code looks harmless. Each line carries an assumption that fails in another locale.
| Assumption in the code | What breaks | Example |
|---|---|---|
| Text is written in the component | Translators must edit source code, and every language needs a code change | `Hello, {name}!` |
| Word order is fixed | Concatenating pieces forces English grammar on other languages | `"Hello, " + name` |
| Plurals are "add an s" | Languages have different plural rules. `item(s)` is a workaround that reads badly | Polish has several plural forms |
| The currency is `$` and the decimal mark is `.` | German writes `1.234,50 €` | `toFixed(2)` |
| Dates are month/day/year | `12/02/2026` means 2 December in some regions and 12 February in others | `en-US` hard-coded |
| Text flows left to right | Arabic and Hebrew read right to left, and a left-aligned layout looks mirrored wrongly | `margin-left` in CSS |
| Strings have a similar length | German words are often longer than English ones, so fixed-width buttons overflow | Button labels |
What internationalisation involves
The rest of this tutorial addresses each failure in turn. The work falls into these areas:
- Identify the user's locale with a standard language tag.
- Move text out of components into message catalogs, which are files that map keys to translated strings.
- Insert variables and markup into messages, so translators control word order.
- Handle plural forms with rules for each language.
- Format numbers, currencies, dates and lists with the browser's
IntlAPIs. - Switch locale at runtime and update the
langanddirattributes on thehtmlelement. - Lay out the interface so it works in both text directions.
A first look at the fix
Compare the Cart component above with the version you will build in later chapters:
import { useTranslation } from 'react-i18next';
export function Cart({ name, count }: { name: string; count: number }) {
const { t } = useTranslation();
return (
<section>
<h1>{t('greeting', { name })}</h1>
<p>{t('items', { count })}</p>
</section>
);
}The component no longer contains English text or grammar. It names a message by key and passes values. The catalog for each locale decides the wording, word order and plural form. Later chapters set up the library that makes t work.
Exercise
A teammate builds the message "You have " + count + " new " + (count === 1 ? "message" : "messages"). Give two reasons this approach fails for other languages.
Show answer
First, it fixes English word order, so a translator cannot move the number or words to fit their grammar. Second, it assumes only two plural forms with an "add s" pattern, but many languages have different or more plural categories. The text is also in code, so each translation needs a code change.
Exercise
Name one thing, other than text, that must change when you support Arabic.
Show answer
The layout direction. Arabic is written right to left, so the dir attribute must be rtl and CSS must not rely on left and right values. Number and date formats may also differ.