JavaScript Intl.Locale and Locale Negotiation
Quick answer
Locale negotiation selects supported formatting settings from requested language tags and runtime data. Intl.Locale represents a Unicode locale identifier and its extensions.
How it works
Intl.getCanonicalLocales normalizes locale tags and removes duplicates. new Intl.Locale(tag) exposes language, script, region and extensions such as calendar and numberingSystem. Formatter constructors accept prioritized locale lists and options; supportedLocalesOf checks requested locales supported without default fallback, while resolvedOptions() reports effective choices. Use explicit numberingSystem: "latn" when machine-friendly display digits are required; do not assume Persian always uses one particular calendar or digit system.
console.log(JSON.stringify(Intl.getCanonicalLocales(["EN-us","en-US","fa-ir"])));Expected output in Node.js:
["en-US","fa-IR"]Tags are canonicalized and duplicates removed in first-occurrence order.
const l=new Intl.Locale("fa-IR-u-nu-latn"); console.log(l.language,l.region,l.numberingSystem);Expected output in Node.js:
fa IR latnThe locale identifier explicitly requests Latin digits.
Common mistakes
Canonicalizing a locale tag does not prove that a particular formatter supports that locale. Negotiated choices can differ from requested settings.
Practice
Compare canonical tags and effective numbering systems for a few explicit locale requests.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
JavaScript Intl.Locale and Locale Negotiation — Knowledge Check
Apply the taught concept and predict the output.
What does Intl.getCanonicalLocales do with equivalent repeated tags?
Which method reports a formatter’s effective locale and settings?
Does constructing Intl.Locale guarantee all formatting services support that tag?
What is the exact console output in JavaScript Intl.Locale and Locale Negotiation example 1?
console.log(JSON.stringify(Intl.getCanonicalLocales(["EN-us","en-US","fa-ir"])));What is the exact console output in JavaScript Intl.Locale and Locale Negotiation example 2?
const l=new Intl.Locale("fa-IR-u-nu-latn"); console.log(l.language,l.region,l.numberingSystem);