Intl.getCanonicalLocales()

Intl.getCanonicalLocales() メソッドは、正規のロケール名を含む配列を返します。重複は省略され、要素は構造的に有効な言語タグとして検証されます。

試してみましょう

構文

Intl.getCanonicalLocales(locales)

引数

locales

標準ロケール名を取得するための String 値リスト。

返値

正規のロケール名を含む配列です。

getCanonicalLocales の使用

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

Intl.getCanonicalLocales("EN_US");
// RangeError:'EN_US' is not a structurally valid language tag

仕様書

Specification
ECMAScript Internationalization API Specification
# sec-intl.getcanonicallocales

ブラウザーの互換性

BCD tables only load in the browser

関連情報