This feature is well established and works across many devices and browser versions. It’s been available across browsers since October 2017.
The Intl.getCanonicalLocales() static method returns an array containing the canonical locale names. Duplicates will be omitted and elements will be validated as structurally valid language tags.
console.log(Intl.getCanonicalLocales("EN-US"));
// Expected output: Array ["en-US"]
console.log(Intl.getCanonicalLocales(["EN-US", "Fr"]));
// Expected output: Array ["en-US", "fr"]
try {
Intl.getCanonicalLocales("EN_US");
} catch (err) {
console.log(err.toString());
// Expected output: RangeError: invalid language tag: "EN_US"
}
Intl.getCanonicalLocales(locales)
An array containing the canonical locale names.
Intl.getCanonicalLocales("EN-US"); // ["en-US"]
Intl.getCanonicalLocales(["EN-US", "Fr"]); // ["en-US", "fr"]
Intl.getCanonicalLocales("EN_US");
// RangeError: invalid language tag: "EN_US"
| Desktop | Mobile | Server | |||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | Bun | Deno | Node.js | |
getCanonicalLocales |
54 | 16 | 48 | 41 | 10.1 | 54 | 56 | 41 | 10.3 | 6.0 | 54 | 10.3 | 1.0.0 | 1.8 | 7.0.0 |
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/getCanonicalLocales