Intl

The ECMAScript Internationalization API uses the Intl object as a namespace for providing language-sensitive features such as string comparison, number formatting, and date and time formatting. The Intl object contains a range of constructors and functions that can be used for this purpose, including functionality that is common to both internationalization constructors and other language-sensitive functions.

Constructor properties

Intl.Collator() Constructor for collators, which are objects that enable language-sensitive string comparison.

Intl.DateTimeFormat() Constructor for objects that enable language-sensitive date and time formatting.

Intl.DisplayNames() Constructor for objects that enable the consistent translation of language, region, and script display names.

Intl.ListFormat() Constructor for objects that enable language-sensitive list formatting.

Intl.Locale() Constructor for objects that represents a Unicode locale identifier.

Intl.NumberFormat() Constructor for objects that enable language-sensitive number formatting.

Intl.PluralRules() Constructor for objects that enable plural-sensitive formatting and language-specific rules for plurals.

Intl.RelativeTimeFormat() Constructor for objects that enable language-sensitive relative time formatting.

Intl.Segmenter() Constructor for objects that enable locale-sensitive text segmentation.

Static methods

Intl.getCanonicalLocales() Returns canonical locale names.

Intl.supportedValuesOf() Returns a sorted array containing the supported unique calendar, collation, currency, numbering systems, or unit values supported by the implementation.

Examples

Formatting dates and numbers You can use Intl to format dates and numbers in a form that’s conventional for a specific language and region:

const count = 26254.39;
const date = new Date("2012-05-24");
function log(locale) {
console.log(
`${new Intl.DateTimeFormat(locale).format(date)} ${new Intl.NumberFormat(
locale,
).format(count)}`,
);
}
log("en-US"); // 5/24/2012 26,254.39
log("de-DE"); // 24.5.2012 26.254,39

For more information on Intl visit MDN Web Docs.


Contributors