Intl.Locale object is a standard built-in property of the Intl object that represents a Unicode locale identifier.

描述

Intl.Locale object was created to allow for easier manipulation of Unicode locales. Unicode represents locales with a string, called a locale identifier . The locale identifier consists of a language identifier and extension tags . Language identifiers are the core of the locale, consisting of language , script ,和 region subtags . Additional information about the locale is stored in the optional extension tags . Extension tags hold information about locale aspects such as calendar type, clock type, and numbering system type.

Traditionally, the Intl API used strings to represent locales, just as Unicode does. This is a simple and lightweight solution that works well. Adding a Locale class, however, adds ease of parsing and manipulating the language, script, and region, as well as extension tags.

构造函数

Intl.Locale()
创建新的 Locale 对象。

实例特性

Intl.Locale.prototype.baseName
Returns basic, core information about the Locale in the form of a substring of the complete data string.
Intl.Locale.prototype.calendar
Returns the part of the Locale that indicates the Locale's calendar era.
Intl.Locale.prototype.caseFirst

Returns whether case is taken into account for the locale's collation rules.

Intl.Locale.prototype.collation
Returns the collation type for the Locale , which is used to order strings according to the locale's rules.
Intl.Locale.prototype.hourCycle

Returns the time keeping format convention used by the locale.

Intl.Locale.prototype.language

Returns the language associated with the locale.

Intl.Locale.prototype.numberingSystem

Returns the numeral system used by the locale.

Intl.Locale.prototype.numeric

Returns whether the locale has special collation handling for numeric characters.

Intl.Locale.prototype.region

Returns the region of the world (usually a country) associated with the locale.

Intl.Locale.prototype.script

Returns the script used for writing the particular language used in the locale.

实例方法

Intl.Locale.prototype.maximize()

Gets the most likely values for the language, script, and region of the locale based on existing values.

Intl.Locale.prototype.minimize()

Gets the most likely values for the language, script, and region of the locale based on existing values.

Intl.Locale.prototype.toString()

Returns the Locale's full locale identifier string.

范例

基本用法

At its very simplest, the Intl.Locale constructor takes a locale identifier string as its argument:

let us = new Intl.Locale('en-US');
					

Using the Locale constructor with an options object

The constructor also takes an optional configuration object argument, which can contain any of several extension types. For example, set the hourCycle property of the configuration object to your desired hour cycle type, and then pass it into the constructor:

let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"});
console.log(us12hour.hourCycle); // Prints "h12"
					

规范

规范
ECMAScript 国际化 API (ECMA-402)

浏览器兼容性

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
Locale Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
Locale() 构造函数 Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 13.0.0
13.0.0
部分支持 12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the Locale instance silently falls back to en-US . To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
baseName Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
calendar Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
caseFirst Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
collation Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
hourCycle Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
language Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
maximize Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale 对象。
WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale 对象。
Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
minimize Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale 对象。
WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale 对象。
Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
numberingSystem Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
numeric Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
region Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
script Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。
toString Chrome 74 Edge 79 Firefox 75 IE No Opera 62 Safari 14 WebView Android 74 Chrome Android 74 Firefox Android No Opera Android 53 Safari iOS 14 Samsung Internet Android 11.0 nodejs 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() 构造函数 了解更多细节。

图例

完整支持

完整支持

不支持

不支持

见实现注意事项。

另请参阅

元数据

  • 最后修改: