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
Locale
in the form of a substring of the complete data string.
Intl.Locale.prototype.calendar
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
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');
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) |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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
12.0.0
|
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
|
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
|
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
|
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
|
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
|
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
|
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
|
maximize
|
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
|
minimize
|
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
|
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
|
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
|
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
|
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
|
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
|
完整支持
不支持
见实现注意事项。
Intl
Collator
DateTimeFormat
ListFormat
NumberFormat
PluralRules
RelativeTimeFormat
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()