Intl.Locale - JavaScript 编辑

The Intl.Locale object is a standard built-in property of the Intl object that represents a Unicode locale identifier.

Description

The Intl.Locale object was created to allow for easier manipulation of Unicode locales. Unicode represents locales with a string, called a locale identifier. The locale identifier consists of a language identifier and extension tags. Language identifiers are the core of the locale, consisting of language, script, and region subtags. Additional information about the locale is stored in the optional extension tags. Extension tags hold information about locale aspects such as calendar type, clock type, and numbering system type.

Traditionally, the Intl API used strings to represent locales, just as Unicode does. This is a simple and lightweight solution that works well. Adding a Locale class, however, adds ease of parsing and manipulating the language, script, and region, as well as extension tags.

Constructor

Intl.Locale()
Creates a new Locale object.

Instance properties

Intl.Locale.prototype.baseName
Returns basic, core information about the Locale in the form of a substring of the complete data string.
Intl.Locale.prototype.calendar
Returns the part of the Locale that indicates the Locale's calendar era.
Intl.Locale.prototype.caseFirst
Returns whether case is taken into account for the locale's collation rules.
Intl.Locale.prototype.collation
Returns the collation type for the Locale, which is used to order strings according to the locale's rules.
Intl.Locale.prototype.hourCycle
Returns the time keeping format convention used by the locale.
Intl.Locale.prototype.language
Returns the language associated with the locale.
Intl.Locale.prototype.numberingSystem
Returns the numeral system used by the locale.
Intl.Locale.prototype.numeric
Returns whether the locale has special collation handling for numeric characters.
Intl.Locale.prototype.region
Returns the region of the world (usually a country) associated with the locale.
Intl.Locale.prototype.script
Returns the script used for writing the particular language used in the locale.

Instance methods

Intl.Locale.prototype.maximize()
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.minimize()
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.toString()
Returns the Locale's full locale identifier string.

Examples

Basic usage

At its very simplest, the Intl.Locale constructor takes a locale identifier string as its argument:

let us = new Intl.Locale('en-US');

Using the Locale constructor with an options object

The constructor also takes an optional configuration object argument, which can contain any of several extension types. For example, set the hourCycle property of the configuration object to your desired hour cycle type, and then pass it into the constructor:

let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"});
console.log(us12hour.hourCycle); // Prints "h12"

Specifications

Specification
ECMAScript Internationalization API (ECMA-402)

Browser compatibility

BCD tables only load in the browser

See also

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:111 次

字数:7812

最后编辑:7年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文