Intl.Locale.prototype.numberingSystem

Intl.Locale 实例的 numberingSystem 访问器属性返回该语言环境的 数字系统

¥The numberingSystem accessor property of Intl.Locale instances returns the numeral system for this locale.

描述

¥Description

数字系统是表达数字的系统。numberingSystem 属性的值是在构造时通过区域设置标识符的 nu 键或通过 Intl.Locale() 构造函数的 numberingSystem 选项设置的。如果两者都存在,则后者优先;如果两者都不存在,则该属性的值为 undefined

¥A numeral system is a system for expressing numbers. The numberingSystem property's value is set at construction time, either through the nu key of the locale identifier or through the numberingSystem option of the Intl.Locale() constructor. The latter takes priority if they are both present; and if neither is present, the property has value undefined.

有关支持的编号系统类型的列表,请参阅 Intl.Locale.prototype.getNumberingSystems()

¥For a list of supported numbering system types, see Intl.Locale.prototype.getNumberingSystems().

示例

¥Examples

与其他区域设置子标签一样,编号系统类型可以通过区域设置字符串或构造函数的配置对象参数添加到 Intl.Locale 对象。

¥Like other locale subtags, the numbering system type can be added to the Intl.Locale object via the locale string, or a configuration object argument to the constructor.

通过区域设置字符串添加编号系统

¥Adding a numbering system via the locale string

Unicode 语言环境字符串规范 中,编号系统类型是区域设置键 "扩展子标签"。这些子标签添加有关区域设置的附加数据,并使用 -u 扩展添加到区域设置标识符中。因此,编号系统类型可以添加到传递到 Intl.Locale() 构造函数的初始区域设置标识符字符串中。要添加编号系统类型,请首先将 -u 扩展键添加到字符串中。接下来,添加 -nu 扩展名以指示你正在添加编号系统。最后,将编号系统类型添加到字符串中。

¥In the Unicode locale string spec, numbering system types are locale key "extension subtags". These subtags add additional data about the locale, and are added to locale identifiers by using the -u extension. Thus, the numbering system type can be added to the initial locale identifier string that is passed into the Intl.Locale() constructor. To add the numbering system type, first add the -u extension key to the string. Next, add the -nu extension to indicate that you are adding a numbering system. Finally, add the numbering system type to the string.

js
const locale = new Intl.Locale("fr-Latn-FR-u-nu-mong");
console.log(locale.numberingSystem); // "mong"

通过配置对象参数添加编号系统

¥Adding a numbering system via the configuration object argument

Intl.Locale() 构造函数有一个可选的配置对象参数,它可以包含多种扩展类型中的任何一种,包括编号系统类型。将配置对象的 numberingSystem 属性设置为所需的编号系统类型,然后将其传递到构造函数中。

¥The Intl.Locale() constructor has an optional configuration object argument, which can contain any of several extension types, including numbering system types. Set the numberingSystem property of the configuration object to your desired numbering system type, and then pass it into the constructor.

js
const locale = new Intl.Locale("en-Latn-US", { numberingSystem: "latn" });
console.log(locale.numberingSystem); // "latn"

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看