Intl.getCanonicalLocales() 方法返回一个数组,数组包含规范的区域语言代码,重复的元素将会被去除,每一个元素都会被验证为格式有效的区域语言代码。

Syntax

Intl.getCanonicalLocales(locales)

参数

locales
想要规范化的字符串数组。

Return value

一个包含规范区域语言代码的数组。

例子

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 Status Comment
ECMAScript Internationalization API 4.0 (ECMA-402)
Intl.getCanonicalLocales
Draft Initial definition

浏览器兼容

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
getCanonicalLocalesChrome Full support 54Edge Full support 16Firefox Full support 48IE No support NoOpera No support NoSafari Full support 11WebView Android No support NoChrome Android No support NoEdge Mobile No support NoFirefox Android Full support 56Opera Android No support NoSafari iOS Full support 11Samsung Internet Android No support Nonodejs No support No

Legend

Full support  
Full support
No support  
No support

参见