Intl.Locale.prototype.maximize()
method gets the most likely values for the language, script, and region of the locale based on existing values.
locale.maximize()
A
Locale
instance whose
baseName
property returns the result of the
Add Likely Subtags
algorithm executed against
locale.baseName
.
Sometimes, it is convenient to be able to identify the most likely locale language identifier subtags based on an incomplete langauage ID. The Add Likely Subtags algorithm gives us this functionality. For instance, given the language ID "en", the algorithm would return "en-Latn-US", since English can only be written in the Latin script, and is most likely to be used in the United States, as it is the largest English-speaking country in the world. This functionality is provided to JavaScript programmers via the
maximize()
方法。
maximize()
only affects the main subtags that comprise the
language identifier
: language, script, and region subtags. Other subtags after the "-u" in the locale indentifier are called extension subtags and are not affected by the
maximize()
method. Examples of these subtags include
Locale.hourCycle
,
Locale.calendar
,和
Locale.numeric
.
let myLocale = new Intl.Locale("fr", {hourCycle: "h24", calendar: "gregory"});
console.log(myLocale.baseName); // Prints "fr"
console.log(myLocale.toString()); // Prints "fr-u-ca-gregory-hc-h24"
let myLocMaximized = myLocale.maximize();
// Prints "fr-Latn-FR". The "Latn" and "FR" tags are added,
// since French is only written in the Latin script and is most likely to be spoken in France.
console.log(myLocMaximized.baseName);
// Prints "fr-Latn-FR-u-ca-gregory-hc-h24".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMaximized.toString());
| 规范 |
|---|
| ECMAScript 国际化 API (ECMA-402) |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
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
|
完整支持
不支持
见实现注意事项。
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()