Working with Internationalization (Intl)

1. Formatting Numbers (Intl.NumberFormat)

Example

new Intl.NumberFormat("en-IN").format(1234567);            // "12,34,567"
new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(99.5);
// "99,50 €"

2. Formatting Dates (Intl.DateTimeFormat)

Example

new Intl.DateTimeFormat("en-GB", { dateStyle: "full", timeStyle: "short" }).format(new Date());
// "Monday, 14 October 2024 at 09:30"

3. Formatting Currencies

OptionUse
style: "currency"Format as money
currency: "USD"ISO 4217 code
currencyDisplay: "code"|"symbol"|"name"Presentation
minimumFractionDigits / maximumFractionDigitsPrecision

4. Comparing Strings (Intl.Collator)

Example

const c = new Intl.Collator("sv", { sensitivity: "base" });
["å", "z", "a"].sort(c.compare); // ["a", "z", "å"]

5. Pluralization (Intl.PluralRules)

Example

const pr = new Intl.PluralRules("en-US");
pr.select(1); // "one"
pr.select(2); // "other"

6. Relative Time (Intl.RelativeTimeFormat)

Example

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

7. List Formatting (Intl.ListFormat)

Example

new Intl.ListFormat("en", { type: "conjunction" }).format(["a","b","c"]);
// "a, b, and c"

8. Display Names (Intl.DisplayNames)

Example

new Intl.DisplayNames("en", { type: "region" }).of("FR"); // "France"
new Intl.DisplayNames("en", { type: "language" }).of("ja"); // "Japanese"

9. Locale Negotiation

APIUse
Intl.getCanonicalLocales(tags)Normalize
Intl.NumberFormat.supportedLocalesOf(...)Find best matches
new Intl.Locale("en-US")Locale object with subtags

10. Loading ICU Data (--with-intl)

BuildDetail
full-icu (default)All locales (~30 MB)
small-icuEnglish only (smaller binary)
NODE_ICU_DATA=/pathLoad ICU data at runtime
--icu-data-dirCLI equivalent