Intl.getCanonicalLocales()

Intl.getCanonicalLocales() 静态方法返回一个包含规范区域设置名称的数组。重复项将被省略,并且元素将被验证为结构上有效的语言标签。

¥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

语法

¥Syntax

js
Intl.getCanonicalLocales(locales)

参数

¥Parameters

locales

要获取规范区域设置名称的 String 值列表。

返回值

¥Return value

包含规范区域设置名称的数组。

¥An array containing the canonical locale names.

示例

¥Examples

使用 getCanonicalLocales

¥Using 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

¥Specifications

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
getCanonicalLocales

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

¥Browser compatibility

也可以看看