Intl.Locale

翻译不完整。 请帮助我们翻译这篇文章!

Intl.Locale 对象是 Intl 对象的标准内置属性,用于表示 Unicode 区域标识。

描述

Intl.Locale 对象是为了更便捷地处理 Unicode 区域设置。Unicode 使用字符串作为区域识别标识。区域标识符由语言标识符扩展标记组成。语言标识符是区域(locale)的核心,包含了语言、脚本和地域子标记(region subtags)。有关区域设置的其他信息体现在可选的扩展标记中。扩展标记保存有关区域设置方面的信息,例如日历类型、时钟类型和编号系统类型。

传统上,Intl 接口像 Unicode 一样使用字符串来表示区域设置,这是一个简单而轻量且效果好的解决方案。但是,添加一个Locale 类可以更容易地解析和操作语言、脚本、区域以及扩展标记。

构造函数

Intl.Locale()
实例化一个 Locale 对象。

实例属性

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.

实例方法

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.

范例

基本使用

很简单,就是需要给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

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
LocaleChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
Locale() constructorChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 13.0.0
Full support 13.0.0
Partial support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the Locale instance silently falls back to en-US. To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
baseNameChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
calendarChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
caseFirstChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
collationChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
hourCycleChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
languageChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
maximizeChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
minimizeChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14
Notes
Full support 14
Notes
Notes Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
numberingSystemChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
numericChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
regionChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
scriptChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
toStringChrome Full support 74Edge Full support 79Firefox Full support 75IE No support NoOpera Full support 62Safari Full support 14WebView Android Full support 74Chrome Android Full support 74Firefox Android No support NoOpera Android Full support 53Safari iOS Full support 14Samsung Internet Android Full support 11.0nodejs Full support 12.0.0
Notes
Full support 12.0.0
Notes
Notes Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.

Legend

Full support  
Full support
No support  
No support
See implementation notes.
See implementation notes.

参阅