Intl.Locale.prototype.minimize()

Intl.Locale 实例的 minimize() 方法尝试删除有关此区域设置的信息,这些信息将通过调用 maximize() 添加。

¥The minimize() method of Intl.Locale instances attempts to remove information about this locale that would be added by calling maximize().

Try it

语法

¥Syntax

js
minimize()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

一个 Intl.Locale 实例,其 baseName 属性返回针对 locale.baseName 执行的 删除可能的子标签 算法的结果。

¥A Intl.Locale instance whose baseName property returns the result of the Remove Likely Subtags algorithm executed against locale.baseName.

描述

¥Description

此方法执行与 maximize() 相反的操作,从区域设置语言标识符中删除任何语言、脚本或区域子标签(本质上是 baseName 的内容)。当语言标识符中有多余的子标签时,这很有用;例如,"拉丁语" 可以简化为 "en",因为 "拉丁语" 是唯一用于书写英语的文字。minimize() 仅影响构成 语言标识符 的主要子标签:语言、脚本和区域子标签。区域设置标识符中 "-u" 之后的其他子标签称为扩展子标签,不受 minimize() 方法的影响。这些子标签的示例包括 hourCyclecalendarnumeric

¥This method carries out the reverse of maximize(), removing any language, script, or region subtags from the locale language identifier (essentially the contents of baseName). This is useful when there are superfluous subtags in the language identifier; for instance, "en-Latn" can be simplified to "en", since "Latn" is the only script used to write English. minimize() 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 minimize() method. Examples of these subtags include hourCycle, calendar, and numeric.

示例

¥Examples

使用最小化

¥Using minimize

js
const myLocale = new Intl.Locale("fr-Latn-FR", {
  hourCycle: "h12",
  calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h12"

const myLocMinimized = myLocale.minimize();

// Prints "fr", since French is only written in the Latin script
// and is most likely to be spoken in France.
console.log(myLocMinimized.baseName);

// Prints "fr-u-ca-gregory-hc-h12".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMinimized.toString());

规范

Specification
ECMAScript Internationalization API Specification
# sec-Intl.Locale.prototype.minimize

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also