Switch your phone's language to English, then open a few apps. Some change right away: English menus, dates as "Dec 12", and prices in the new format. Others are a mess: English menus, Indonesian buttons, and a label cut off halfway.
The apps that change right away were prepared for this from the start. That preparation is called internationalization, shortened to i18n (the letter i, 18 letters in between, then the letter n). i18n means preparing a page so it can appear in another language and another region's conventions (such as how numbers and dates are written) without rewriting its code. Filling in the translation for one language is called localization (l10n). Think of the price board outside Mist Homestay. If Mrs. Sri paints the whole sentence straight onto the board, every foreign guest needs a new board. If the board has slots, empty places for the room name, price and date, with cards that can be swapped, she only swaps the cards. i18n builds the slots; l10n fills in the cards. On a web page, a slot is a place for text in the code, and a card is the translated text for one language.
Text moves out of the code
Step one: every piece of text on the page moves into one dictionary per language. A dictionary here is a list of texts, and each text has a key, its short name. The code only names the key. In the JavaScript code below, messages holds two dictionaries, id and en. The last line fills the .book button with the text whose key is book, from the dictionary of the language in use:
const messages = {
id: { book: 'Pesan kamar, bayar di tempat', cancel: 'Gratis batal sampai 3 hari sebelum check-in.' },
en: { book: 'Book now, pay at the homestay', cancel: 'Free cancellation up to 3 days before check-in.' },
};
const locale = 'en-US';
const lang = locale.slice(0, 2); // 'en'
document.querySelector('.book').textContent = messages[lang].book;
- Every language has the same keys (
book,cancel), and the values are whole sentences, not fragments. - A locale is a language code plus a region:
id-ID(Indonesian, Indonesia),en-US(English, United States),en-GB(English, Britain). The region decides how numbers and dates look.locale.slice(0, 2)takes its first two letters,'en', to pick the dictionary. - Don't glue fragments together.
'Total for ' + n + ' nights'can't be translated, because another language may need the words in a different order, and the code even writes "1 nights". - Libraries (ready-made code written by other people) such as react-i18next and FormatJS work the same way. BelajarWeb.dev itself uses react-i18next with the dictionaries
id.jsonanden.json.
Numbers and money: Intl.NumberFormat
Mrs. Sri's page writes the price with '$' + total.toLocaleString(). toLocaleString() is a JavaScript function that writes a number with thousands separators. Mr. Hadi opens the page on a laptop whose browser language is German. What does the Garden Room's 3-night total (127.5) show? Guess before you look at the table.
Intl.NumberFormat is the browser's built-in number formatter. It knows each locale's rules: the thousands separator, the decimal mark and the currency symbol. We ran it in Chromium 156, Firefox 148 and WebKit 26.4 (Safari's engine):
| Code | Chrome | Firefox | Safari |
|---|---|---|---|
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR' }).format(700000) |
Rp 700.000 | Rp 700.000,00 | Rp700.000,00 |
the same, plus minimumFractionDigits: 0, maximumFractionDigits: 0 |
Rp 700.000 | Rp 700.000 | Rp700.000 |
new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'USD' }).format(127.5) |
127,50 $ | 127,50 $ | 127,50 $ |
new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(1234.5) |
$1,234.50 | $1,234.50 | $1,234.50 |
(127.5).toLocaleString() in a German browser |
127,5 | 127,5 | 127,5 |
style: 'currency'pluscurrency: 'USD'adds the currency symbol. The currency is given apart from the locale, because a German guest still pays in dollars.- Indonesia uses a dot for thousands and a comma for decimals.
Intl.NumberFormat("id-ID", { style: "currency", currency: "IDR", minimumFractionDigits: 2 })formats 1234567.89 as Rp 1.234.567,89 in all three browsers.minimumFractionDigits: 2means at least 2 digits after the decimal mark.en-USis the other way round: a comma for thousands, a dot for decimals. - Browsers disagree on rupiah decimals. New versions of Chrome give the rupiah 0 decimal places, so with no decimal options 1234567.89 is rounded to Rp 1.234.568. Firefox and Safari still give it 2, so
,00appears. So always setminimumFractionDigitsandmaximumFractionDigits(the fewest and the most decimal places) yourself. - USD always gets 2 decimals: 1000 becomes $1,000.00, and 0 becomes $0.00.
So the answer to the guess: $127,5, with a comma and only one decimal. toLocaleString() without a locale uses the browser's language. On a German laptop the decimal mark is a comma, so the page puts a dollar sign before a German number, and the second decimal is missing.
Dates: Intl.DateTimeFormat
Intl.DateTimeFormat is the browser's built-in date formatter. This code writes the check-in date, 12 December 2026, in three locales:
const checkIn = new Date(2026, 11, 12); // months count from 0: 11 = December
new Intl.DateTimeFormat('id-ID', { day: 'numeric', month: 'short' }).format(checkIn); // "12 Des"
new Intl.DateTimeFormat('en-US', { day: 'numeric', month: 'short' }).format(checkIn); // "Dec 12"
new Intl.DateTimeFormat('en-GB', { day: 'numeric', month: 'short' }).format(checkIn); // "12 Dec"
The results are the same in all three browsers. Two things often go wrong:
- A date in numbers only is ambiguous. It can be read two ways. 3 January 2027 becomes
3/1/2027inid-IDand1/3/2027inen-US, which a reader used toid-IDtakes as 1 March. Use the month's name (month: 'short'). - The time zone.
new Date('2024-06-15T00:00:00Z')is midnight UTC (the world's reference time zone; theZat the end means UTC). In a browser whose zone is Los Angeles,new Intl.DateTimeFormat('en-US').format(...)gives6/14/2024, a day early. Add{ timeZone: 'UTC' }so the result is6/15/2024everywhere. With the same option,'2024-01-02T00:00:00Z'becomes1/2/2024.
Plurals: Intl.PluralRules
Indonesian doesn't change a noun for a count: 1 malam, 2 malam. English has two forms: 1 night, 2 nights. Arabic has six. Intl.PluralRules says which plural category applies to a number. In this code, the first three lines ask for the category. The lines after them use the answer to pick a word from nightWord:
new Intl.PluralRules('id-ID').select(2); // "other": Indonesian's only category
new Intl.PluralRules('en-US').select(1); // "one"
new Intl.PluralRules('en-US').select(2); // "other"
const nightWord = { id: { other: 'malam' }, en: { one: 'night', other: 'nights' } };
const rule = new Intl.PluralRules(locale).select(nights);
const label = `${nights} ${nightWord[lang][rule]}`; // "1 night", "2 nights"
We checked resolvedOptions().pluralCategories (the list of a locale's categories) in all three browsers: id has only other, en has one and other, and ar has zero, one, two, few, many, other. Don't write n === 1 ? 'night' : 'nights' (if n equals 1, write night, otherwise nights) yourself. That rule is wrong for many other languages. In react-i18next and FormatJS, the plural forms go in the dictionary under the same rules.
Text that grows
Translations are rarely the same length. In BelajarWeb.dev's own dictionaries (21,318 strings found in both id.json and en.json), the Indonesian is 2.1% shorter in total. But for short labels (up to 10 letters in English), the Indonesian is on average 15.4% longer. "Search" becomes "Cari", but "Save" becomes "Simpan", and "Settings" becomes "Pengaturan". IBM's guidance, quoted in the W3C article "Text size in translation", shows the same pattern from English into other languages: text up to 10 letters can grow 200 to 300%, and text over 70 letters about 130%.
Mrs. Sri's booking button was made to fit the Indonesian text. We measured its two labels from the dictionary above in Chromium 147 (system font, 16px, weight 600):
| Button text | Text width | In a button with width: 256px; padding: 0 16px (224px of room) |
|---|---|---|
| Pesan kamar, bayar di tempat | 223.4px | fits |
| Book now, pay at the homestay | 235.2px | cut by 11.2px |
The CSS below fixes it. min-inline-size means a minimum width (names like this are covered in the logical properties section below):
.book {
min-inline-size: 16rem; /* may get wider, never narrower */
max-inline-size: 100%;
padding-inline: 16px;
white-space: normal; /* longer text wraps to a second line instead of being cut */
}
Fonts differ per system, so the numbers differ on Windows or Android. But the problem is the same: a button size locked to fit one language.
lang, dir and logical properties
<html lang="en"> states the page's language. A screen reader picks its voice and pronunciation from this attribute (WCAG 3.1.1 Language of Page). hyphens: auto (breaking words at the end of a line with a hyphen) also breaks words by that language's rules. A phrase in another language inside the page gets its own lang (WCAG 3.1.2 Language of Parts).
dir="rtl" (right-to-left) flips the writing direction for languages written from right to left, such as Arabic. To make the layout flip too, use logical properties: CSS properties that name the start and end of a line, not left and right. In English, a line starts on the left. In Arabic, a line starts on the right. The word inline in their names means along the line of text.
| Physical (left and right) | Logical (start and end) |
|---|---|
padding-left |
padding-inline-start |
margin-right |
margin-inline-end |
left |
inset-inline-start |
width |
inline-size |
text-align: left |
text-align: start |
We set dir="rtl", then read the result in all three browsers. padding-inline-start: 16px moved to the right. padding-left: 16px stayed on the left, so it is now on the wrong side. text-align: start followed to the right. With logical properties the browser flips things itself, so no second stylesheet (CSS file) for RTL is needed.
⚠️ What breaks a page in another language
toLocaleString()without a locale. The result follows the browser's language: "$127,5" on a German laptop. Always name the locale.- Gluing sentence fragments. Word order and plurals differ per language. Keep whole sentences with slots.
- Comparing formatted output with an ordinary space. Chrome and Firefox put a no-break space (U+00A0, a space that keeps "Rp" and the number on one line) in "Rp 700.000", while Safari puts no space at all. A test (code that checks a result) that types
'Rp 700.000'with an ordinary space fails in every browser. - Dates without
timeZoneand dates in numbers only. The date is a day off in another zone, and 3/1 is read two ways. - Fixed widths and
padding-left. English text gets cut, and an RTL layout doesn't flip. Usemin-inline-sizeand logical properties.
TL;DR: i18n (internationalization) prepares the slots, the places for text that can be swapped, and l10n (localization) fills in the translation. Text moves out of the code into one dictionary (a list of texts) per language, as whole sentences. The locale, a language code plus a region (id-ID, en-US), decides the format. Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }) (the browser's built-in number formatter) gives commas between thousands and the $ symbol: $1,234.50 and $1,000.00. For other currencies the decimals can differ by browser (rupiah in id-ID: Chrome Rp 1.234.568, Firefox Rp 1.234.567,89), so set the number of decimals yourself with minimumFractionDigits and maximumFractionDigits. toLocaleString() (a function that writes numbers) without a locale follows the browser's language and can write $127,5. Intl.DateTimeFormat (the date formatter) gives "12 Des" or "Dec 12". Use month names, and timeZone: 'UTC' so a date is not a day off in another time zone (6/15/2024, not 6/14/2024). Intl.PluralRules picks the plural category: Indonesian only has other, English one and other. Short Indonesian labels are on average 15.4% longer than English ones, and a translation can outgrow a button: use min-inline-size (a minimum width), not a fixed width. lang states the page's language (WCAG 3.1.1). Logical properties such as padding-inline-start name the start of a line, not the left, so they flip by themselves under dir="rtl" (right-to-left writing).
⚡ Slots first, translations later
Meaning: i18n (internationalization) prepares a page so it can appear in another language and another region's conventions without rewriting its code. l10n (localization) fills in the translation for one language. Every piece of text moves out of the code into one dictionary (a list of texts) per language, as whole sentences. The code only names each text's key (its short name).
⚡ Numbers and money with Intl.NumberFormat
Guess first: Mrs. Sri's page writes the price with '$' + total.toLocaleString() (a JavaScript function that writes a number with thousands separators). Mr. Hadi opens it on a laptop whose browser language is German. What does the Garden Room's 3-night total (127.5) show?
$127,5, with a comma and only one decimal. toLocaleString() without a locale (a language and region code, such as en-US) follows the browser's language.
Meaning: To write a price in US dollars, use Intl.NumberFormat("en-US", { style: "currency", currency: "USD" }). The en-US locale decides the commas between thousands and the decimal dot, and currency: "USD" adds the $ symbol and two decimals. For other currencies, also set minimumFractionDigits and maximumFractionDigits (the fewest and the most decimal places). Without them, 1234567.89 in rupiah (id-ID, IDR) becomes Rp 1.234.568 in new versions of Chrome and Rp 1.234.567,89 in Firefox and Safari.
⚡ A button that fits both languages
Write:
.book {
min-inline-size: 16rem; /* may get wider, never narrower */
max-inline-size: 100%;
padding-inline: 16px;
white-space: normal; /* longer text wraps to a second line instead of being cut */
}
Meaning: Translations are rarely the same length. Mrs. Sri's booking button has 224px of room for its text, which fits the Indonesian label "Pesan kamar, bayar di tempat". The English label, "Book now, pay at the homestay", is 235.2px wide, so it gets cut. With min-inline-size (a minimum width), the button may grow or the text may wrap to a second line, and the text is never cut.