Intl.Locale.prototype.minimize() - JavaScript 编辑
The Intl.Locale.prototype.minimize()
method attempts to remove information about the locale that would be added by calling Locale.maximize()
.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.Syntax
locale.minimize()
Return value
A Locale
instance whose baseName
property returns the result of the Remove Likely Subtags algorithm executed against locale.baseName
.
Description
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 indentifier are called extension subtags and are not affected by the minimize()
method. Examples of these subtags include Locale.hourCycle
, Locale.calendar
, and Locale.numeric
.
Examples
Using minimize
let myLocale = new Intl.Locale("fr-Latn-FR", {hourCycle: "h24", calendar: "gregory"});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h24"
let 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-h24".
// Note that the extension tags (after "-u") remain unchanged.
console.log(myLocMinimized.toString());
Specifications
Specification |
---|
ECMAScript Internationalization API (ECMA-402) |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论