The Browser's Intl API — i18n

Intl formats by locale with the CLDR data each browser carries through ICU. The pattern is always the same: new Intl.X(locale, options), then format()…

The UI/UX lesson "Internationalization (i18n)" already used NumberFormat, DateTimeFormat and PluralRules for Mrs. Sri's card. Those are only three members of the Intl family, JavaScript's set of built-in formatters for numbers, money, dates, relative times, plurals, lists, alphabetical order, language names and text splitting, all following a locale. Here we take all of them apart. They work like the Mist Homestay receptionist who knows every country's habits by heart: hand her a number, a date or a list of rooms plus the guest's locale, and she writes it the way that guest expects. What she knows comes from one big book, CLDR (the Unicode Common Locale Data Repository), which every browser carries through the ICU library. Each browser carries a different edition, so the answers sometimes differ a little, and we measure those differences too.

One pattern for every formatter

const money = new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });
money.format(70);                // "$70"
money.formatToParts(70);         // [{ type: "currency", value: "$" }, { type: "integer", value: "70" }]
money.resolvedOptions().locale;  // "ja-JP"

When the browser has no data for the locale you asked for, it quietly switches to another one. Mrs. Sri wants a Javanese version (jv): new Intl.NumberFormat('jv').resolvedOptions().locale gives "jv" in Firefox 146, Safari 26.4 and Node 22.22.1, but "en-US" in Chromium 147, because Chrome doesn't ship Javanese data and falls back to the browser's default language. Give a fallback list: with ['jv', 'id'], Chrome picks "id" and writes "Sabtu, 12 Desember 2026".

NumberFormat: how many decimals does the rupiah have?

Mrs. Sri's prices are in US dollars, and the dollar has 2 decimals in every engine. Not every currency is that simple. We ran the same code for the Indonesian rupiah (IDR), the currency of the id-ID locale. It ran in three browser engines (through Playwright) and in Node 22.22.1, which carries ICU 78.2 with CLDR 48:

Code Chromium 147 Firefox 146 WebKit 26.4 (Safari) Node 22.22.1
new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR' }).format(700000) Rp 700.000,00 Rp 700.000,00 Rp700.000,00 Rp 700.000
.resolvedOptions().maximumFractionDigits for IDR 2 2 2 0
the same, plus maximumFractionDigits: 0 Rp 700.000 Rp 700.000 Rp700.000 Rp 700.000
new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'JPY' }).format(9800) ¥9,800 ¥9,800 ¥9,800 ¥9,800
new Intl.NumberFormat('ar-EG', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format(70) ٧٠ US$ ٧٠ US$ ٧٠ US$ ٧٠ US$

Each currency's number of decimals comes from data. The ISO 4217 table lists the rupiah with 2 decimals. CLDR said 2 as well up to CLDR 47, then CLDR 48 (October 2025) changed IDR to 0 decimals. V8, the JavaScript engine of Chrome and Node, takes decimals from the CLDR inside its ICU: Node 22.22.1 already carries CLDR 48, so 0; Chromium 147 still gives 2, while Chromium 156 already gives 0. Firefox and Safari use the ISO 4217 table, so 2. The result: different, even though the code is identical.

The rule: for rupiah, always say maximumFractionDigits: 0, so every engine stops at 0 decimals. More from the table:

DateTimeFormat and timeZone

Mrs. Sri's check-in: Saturday, 12 December 2026, at 14:00 in the homestay's time zone (Asia/Singapore), which is 06:00 UTC.

const checkIn = new Date('2026-12-12T06:00:00Z');
const opts = { dateStyle: 'full', timeStyle: 'short', timeZone: 'Asia/Singapore' };

new Intl.DateTimeFormat('en-US', opts).format(checkIn); // "Saturday, December 12, 2026 at 2:00 PM"
new Intl.DateTimeFormat('id-ID', opts).format(checkIn); // "Sabtu, 12 Desember 2026 pukul 14.00"
new Intl.DateTimeFormat('ja-JP', opts).format(checkIn); // "2026年12月12日土曜日 14:00"
new Intl.DateTimeFormat('ar-EG', opts).format(checkIn); // "السبت، ١٢ ديسمبر ٢٠٢٦ في ٢:٠٠ م"

new Intl.DateTimeFormat('en-US', { dateStyle: 'long', timeZone: 'Asia/Singapore' }).format(checkIn); // "December 12, 2026"

RelativeTimeFormat, PluralRules, ListFormat

const rtf = new Intl.RelativeTimeFormat('en-US', { numeric: 'auto' });
rtf.format(3, 'day');    // "in 3 days"
rtf.format(1, 'day');    // "tomorrow"
rtf.format(-1, 'day');   // "yesterday"

Collator, DisplayNames, Segmenter

const guests = ['Zahra', 'Ömer', 'Oscar', 'andi', 'Mrs. Sri', 'Émile'];
[...guests].sort();                                 // ["Mrs. Sri", "Oscar", "Zahra", "andi", "Émile", "Ömer"]
[...guests].sort(new Intl.Collator('en').compare);  // ["andi", "Émile", "Mrs. Sri", "Ömer", "Oscar", "Zahra"]
[...guests].sort(new Intl.Collator('sv').compare);  // ["andi", "Émile", "Mrs. Sri", "Oscar", "Zahra", "Ömer"]

const rooms = ['Room 10', 'Room 2', 'Room 1'];
rooms.sort(new Intl.Collator('en', { numeric: true }).compare); // ["Room 1", "Room 2", "Room 10"]

📌 How the engines differ, measured

Every result above is the same in the four engines, except the ones in this table:

Measured Chromium 147 Firefox 146 WebKit 26.4 Node 22.22.1
Default IDR decimals 2 2 2 0
After "Rp" in id-ID U+00A0 U+00A0 nothing U+00A0
JPY symbol in ja-JP ¥ ¥ ¥ ¥
ar-SA calendar gregory gregory islamic-umalqura gregory
Javanese data (jv) none, falls back to en-US yes yes yes
The "3" in a ja word Segmenter isWordLike isWordLike not isWordLike isWordLike
ListFormat ar-EG plain plain each item wrapped in U+2068 and U+2069 plain

The versions: Chromium 147.0.7727.15, Firefox 146.0.1 and WebKit 26.4 from Playwright, and Node 22.22.1 with ICU 78.2, CLDR 48 and Unicode 17.0. We measured again on 29 October 2026 with Chromium 156.0.8078.4 and Firefox 148.0.2 from Playwright: Firefox 148 matches the Firefox 146 column exactly, and Chromium 156 differs in one row only, the default IDR decimals, which are now 0 as in Node. The Lab runs the same code in your browser and puts this table next to it.

⚠️ When Intl output catches you out

TL;DR: Intl formats by locale with the CLDR data each browser carries through ICU. The pattern is always the same: new Intl.X(locale, options), then format(), formatToParts(), and resolvedOptions() to see what was really used; toLocaleString is only a shortcut to Intl.NumberFormat. NumberFormat: the default IDR decimals are 2 in Chrome 147, Firefox 146 and Safari 26.4 but 0 in Node 22.22.1 (CLDR 48) and Chrome 156, so say maximumFractionDigits: 0. DateTimeFormat: dateStyle: 'long' for "December 12, 2026", always with timeZone: 'Asia/Singapore'; Safari uses the Hijri calendar for ar-SA. RelativeTimeFormat writes "in 3 days", PluralRules picks the category (ar has six), ListFormat joins lists, Collator sorts like a dictionary (and numeric: true puts "Room 2" before "Room 10"), DisplayNames writes "日本語" and "العربية", Segmenter splits Japanese text that has no spaces. Chrome 147 has no Javanese data, so check resolvedOptions().locale.

⚡ One pattern for every formatter

Write:

const money = new Intl.NumberFormat('ja-JP', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 });
money.format(70);                // "$70"
money.resolvedOptions().locale;  // "ja-JP"

Meaning: The constructor takes a locale and options, and you create it once and use it many times. format() gives the finished text, resolvedOptions() tells you what was really used.

⚡ How many decimals does the rupiah have?

Guess first: does new Intl.NumberFormat('id-ID', { style: 'currency', currency: 'IDR' }).format(700000), the Indonesian rupiah in the id-ID locale, give the same result in Chromium 147 and in Node 22.22.1?

No. Chromium 147 writes Rp 700.000,00, Node 22.22.1 writes Rp 700.000. The number of IDR decimals comes from the data each engine carries.

Meaning: Identical code can give different results. For rupiah, always say maximumFractionDigits: 0, so every engine stops at 0 decimals.

⚡ A date in English, on the homestay's clock

Write:

new Intl.DateTimeFormat('en-US', { dateStyle: 'long', timeZone: 'Asia/Singapore' }).format(checkIn); // "December 12, 2026"

Meaning: dateStyle: 'long' writes the full date in the locale's language. timeZone decides which clock time is written: without it, a guest's laptop in Tokyo writes 15:00, while check-in is at 14:00 at the homestay.

What you will learn