Spec-Zone.ru › JavaScript

Intl.getCanonicalLocales()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It's been available across browsers since September 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.

Try it

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"
}

Syntax

Intl.getCanonicalLocales(locales)

Parameters

locales
A list of String values for which to get the canonical locale names.

Return value

An array containing the canonical locale names.

Examples

Using getCanonicalLocales

Intl.getCanonicalLocales("EN-US"); // ["en-US"]
Intl.getCanonicalLocales(["EN-US", "Fr"]); // ["en-US", "fr"]

Intl.getCanonicalLocales("EN_US");
// RangeError: invalid language tag: "EN_US"

Specifications

Specification
ECMAScript® 2027 Internationalization API Specification
# sec-intl.getcanonicallocales

Browser compatibility

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

See also

  • Polyfill of Intl.getCanonicalLocales in FormatJS
  • Intl.NumberFormat.supportedLocalesOf()
  • Intl.DateTimeFormat.supportedLocalesOf()
  • Intl.Collator.supportedLocalesOf()

© 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

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API