What is the `Intl` namespace object for?
TL;DR
Intl provides locale-aware formatting and comparison for numbers, currencies, dates, times, lists, relative time, plural categories, segments, and more. Pass the locale and domain options explicitly rather than hand-building localized strings. For dates, specify the intended time zone; for money, store the currency separately from the numeric amount. Exact output can vary with locale data, so test semantic parts rather than brittle punctuation where possible.
The Intl namespace object in JavaScript is a part of the ECMAScript Internationalization API, which provides language-sensitive string comparison, number formatting, and date and time formatting. This is particularly useful for applications that need to support multiple languages and regions.
Language-sensitive string comparison
The Intl.Collator object is used for comparing strings in a locale-aware manner. This is useful for sorting strings in a way that is consistent with the conventions of a particular language.
Number formatting
The Intl.NumberFormat object is used for formatting numbers according to the conventions of a specific locale. This includes formatting for currency, percentages, and plain numbers.
Date and time formatting
The Intl.DateTimeFormat object is used for formatting dates and times according to the conventions of a specific locale.
Plural rules
The Intl.PluralRules object is used to get the plural form of a number in a specific locale. This is useful for correctly pluralizing words in different languages.
Intl.PluralRules returns a category; the application still provides translated message forms. English-style count === 1 ? singular : plural logic does not generalize to every language.
Practical considerations
- Reuse a formatter when formatting many values instead of constructing one for every table cell.
- Use
formatToParts()when markup must wrap specific semantic pieces; do not split a formatted string on assumed punctuation. - Locale fallback and supported options depend on the runtime's locale data. Use
supportedLocalesOf()when exact locale support matters. Intlformats values but does not translate arbitrary product copy or convert time zones into business-calendar rules.