Intl.getCanonicalLocales() method returns an array containing the canonical locale names. Duplicates will be omitted and elements will be validated as structurally valid language tags.

The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.

句法

Intl.getCanonicalLocales(locales)
					

参数

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

返回值

An array containing the canonical locale names.

范例

Using getCanonicalLocales

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
					

规范

规范
ECMAScript 国际化 API (ECMA-402)
The definition of 'Intl.getCanonicalLocales' in that specification.

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
getCanonicalLocales Chrome 54 Edge 16 Firefox 48 IE No Opera No Safari 11 WebView Android No Chrome Android No Firefox Android 56 Opera Android No Safari iOS 11 Samsung Internet Android No nodejs 7.0.0

图例

完整支持

完整支持

不支持

不支持

另请参阅

元数据

  • 最后修改: