Intl.Locale.prototype.maximize()
Intl.Locale
实例的 maximize()
方法根据现有值获取该语言环境的语言、脚本和区域最可能的值。
¥The maximize()
method of Intl.Locale
instances gets the
most likely values for the language, script, and region of this locale based on
existing values.
Try it
语法
参数
返回值
¥Return value
一个 Intl.Locale
实例,其 baseName
属性返回针对 locale.baseName
执行的 添加可能的子标签 算法的结果。
¥A Intl.Locale
instance whose baseName
property returns
the result of the Add Likely Subtags algorithm executed against locale.baseName
.
描述
¥Description
有时,能够根据不完整的语言 ID 识别最可能的区域设置语言标识符子标签会很方便。添加可能的子标签算法为我们提供了此功能。例如,给定语言 ID "en",算法将返回 "美国拉丁语",因为英语只能用拉丁字母书写,并且最有可能在美国使用,因为美国是世界上最大的英语国家 。此功能通过 maximize()
方法提供给 JavaScript 程序员。maximize()
仅影响构成 语言标识符 的主要子标签:语言、脚本和区域子标签。区域设置标识符中 "-u" 之后的其他子标签称为扩展子标签,不受 maximize()
方法的影响。这些子标签的示例包括 hourCycle
、calendar
和 numeric
。
¥Sometimes, it is convenient to be able to identify the most likely locale language
identifier subtags based on an incomplete language 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()
method. maximize()
only
affects the main subtags that comprise the language identifier: language, script, and region subtags.
Other subtags after the "-u" in the locale identifier are called extension subtags and
are not affected by the maximize()
method. Examples of these subtags
include hourCycle
,
calendar
, and numeric
.
示例
使用最大化
¥Using maximize
const myLocale = new Intl.Locale("fr", {
hourCycle: "h12",
calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr"
console.log(myLocale.toString()); // Prints "fr-u-ca-gregory-hc-h12"
const 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-h12".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMaximized.toString());
规范
Specification |
---|
ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.maximize |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also
Intl.Locale
baseName
- Unicode 区域设置数据标记语言规范中的 可能的子标签