Intl.Locale.prototype.language
property is an accessor property that returns the language associated with the locale.
Language is one of the core features of a locale. The Unicode specification treats the language identifier of a locale as the language and the region together (to make a distiction between dialects and variations, e.g. British English vs. American English). The
language
property of a
Locale
returns strictly the locale's language subtag.
In order to be a valid Unicode locale identifier, a string must start with the language subtag. The main argument to the
Locale
constructor must be a valid Unicode locale identifier, so whenever the constructor is used, it must be passed an identifier with a language subtag.
let langStr = new Intl.Locale("en-Latn-US");
console.log(langStr.language); // Prints "en"
While the language subtag must be specified, the
Locale
constructor takes a configuration object, which can override the language subtag.
let langObj = new Intl.Locale("en-Latn-US", {language: "es"});
console.log(langObj.language); // Prints "es"
| 规范 |
|---|
| ECMAScript 国际化 API (ECMA-402) |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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
|
完整支持
不支持
见实现注意事项。
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()