--- title: Intl.Locale slug: Web/JavaScript/Reference/Global_Objects/Intl/Locale translation_of: Web/JavaScript/Reference/Global_Objects/Intl/Locale ---
Intl.Locale 对象是 Intl 对象的标准内置属性,用于表示 Unicode 区域标识。
Intl.Locale 对象是为了更便捷地处理 Unicode 区域设置。Unicode 使用字符串作为区域识别标识。区域标识符由语言标识符和扩展标记组成。语言标识符是区域(locale)的核心,包含了语言、脚本和地域子标记(region subtags)。有关区域设置的其他信息体现在可选的扩展标记中。扩展标记保存有关区域设置方面的信息,例如日历类型、时钟类型和编号系统类型。
传统上,Intl 接口像 Unicode 一样使用字符串来表示区域设置,这是一个简单而轻量且效果好的解决方案。但是,添加一个Locale 类可以更容易地解析和操作语言、脚本、区域以及扩展标记。
Locale 对象。Intl.Locale.prototype.baseNameLocale in the form of a substring of the complete data string.Intl.Locale.prototype.calendarLocale that indicates the Locale's calendar era.Intl.Locale.prototype.caseFirstIntl.Locale.prototype.collationLocale, which is used to order strings according to the locale's rules.Intl.Locale.prototype.hourCycleIntl.Locale.prototype.languageIntl.Locale.prototype.numberingSystemIntl.Locale.prototype.numericIntl.Locale.prototype.regionIntl.Locale.prototype.scriptIntl.Locale.prototype.maximize()Intl.Locale.prototype.minimize()Intl.Locale.prototype.toString()很简单,就是需要给{{jsxref("Locale/Locale", "Intl.Locale")}} 构造函数传入一个 locale 标识字符串作为参数:
let us = new Intl.Locale('zh-Hans-CN');
构造函数支持传入 object 作为配置,object 中可包含多个配置属性。例如,设置 hourCycle 属性,用于设置您所需要的小时周期类型:
let zh12hour = new Intl.Locale("zh-Hans-CN", {hourCycle: "h12"});
console.log(zh12hour.hourCycle); // Prints "h12"
| Specification | Status | Comment |
|---|---|---|
| Intl.Locale proposal | Stage 3 |
{{Compat("javascript.builtins.Intl.Locale")}}