Glossary / Internationalization APIs
Internationalization APIs
The ECMAScript Intl namespace provides locale-sensitive formatting, sorting, plural selection, relative-time output, display names, lists, and text segmentation. It delegates complex language and regional rules to locale data (commonly ICU/CLDR-backed), avoiding fragile hand-written assumptions. An internationalized interface still needs product decisions about locale, input parsing, time zones, fallback, and accessibility.
Core APIs
Intl.NumberFormat: numbers, currency, percentages, units, compact notation, and rounding options.Intl.DateTimeFormat: date/time display, calendar, numbering system, and explicit time-zone selection.Intl.Collator: locale-aware comparison and sorting; configure sensitivity and numeric behavior.Intl.PluralRules: select locale-specific plural categories.Intl.RelativeTimeFormatandIntl.ListFormat: natural relative-time and list presentation.Intl.DisplayNamesandIntl.Segmenter: localized names and segmentation into graphemes/words/sentences.
new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" })
.format(1234.5); // locale-specific punctuation and currency placement
Formatting is not parsing: NumberFormat does not provide a universal locale-aware parser. Runtime locale data and defaults can differ; specify options for deterministic tests and server rendering. Server/client locale or time-zone mismatch can cause hydration text differences. Feature-detect optional APIs and test important locales, including RTL and non-Latin digits.
Engineering guidance
Use BCP 47 locale identifiers and a documented fallback policy. Keep canonical data separate from display strings. Do not hard-code separators, month names, plural rules, or sort order. Test output semantics, not exact punctuation alone, unless the locale and runtime data are pinned.
Interview questions
- Which Intl API sorts text for a locale?
Intl.Collator. - Does NumberFormat parse localized numbers? No; it formats them.
- Why specify a time zone? To avoid host-dependent results and express the intended display zone.
- Why might SSR hydration differ? Server/client locale, time zone, or locale-data versions may differ.