Intl.NumberFormat.supportedLocalesOf()
Intl.NumberFormat.supportedLocalesOf()
静态方法返回一个数组,其中包含数字格式支持的所提供区域设置,而无需回退到运行时的默认区域设置。
¥The Intl.NumberFormat.supportedLocalesOf()
static method returns an array containing those of the provided locales that are supported in number formatting without having to fall back to the runtime's default locale.
Try it
语法
参数
¥Parameters
locales
-
带有 BCP 47 语言标记的字符串,或此类字符串的数组。有关
locales
论证的一般形式和解释,请参阅Intl
主页参数说明。 options
Optional-
可能具有以下属性的对象:
localeMatcher
-
要使用的区域设置匹配算法。可能的值为
"lookup"
和"best fit"
;默认为"best fit"
。有关此选项的信息,请参阅 Intl 页。
返回值
示例
使用 supportedLocalesOf()
¥Using supportedLocalesOf()
假设运行时在数字格式方面支持印度尼西亚语和德语,但不支持巴厘岛语,supportedLocalesOf
将返回印度尼西亚语和德语语言标签不变,尽管 pinyin
排序规则既不与数字格式相关,也不与印度尼西亚语一起使用,并且不太可能为印度尼西亚语提供专门的德语。 支持的。请注意此处 "lookup"
算法的规范 - "best fit"
匹配器可能会认为印度尼西亚语足以匹配巴厘岛语,因为大多数巴厘岛人也理解印度尼西亚语,因此也返回巴厘岛语语言标签。
¥Assuming a runtime that supports Indonesian and German but not Balinese in number formatting, supportedLocalesOf
returns the Indonesian and German language tags unchanged, even though pinyin
collation is neither relevant to number formatting nor used with Indonesian, and a specialized German for Indonesia is unlikely to be supported. Note the specification of the "lookup"
algorithm here — a "best fit"
matcher might decide that Indonesian is an adequate match for Balinese since most Balinese speakers also understand Indonesian, and therefore return the Balinese language tag as well.
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.NumberFormat.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
规范
Specification |
---|
ECMAScript Internationalization API Specification # sec-intl.numberformat.supportedlocalesof |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also