Intl.ListFormat.supportedLocalesOf()

Intl.ListFormat.supportedLocalesOf() 静态方法返回一个数组,其中包含列表格式中支持的所提供的区域设置,而不必回退到运行时的默认区域设置。

¥The Intl.ListFormat.supportedLocalesOf() static method returns an array containing those of the provided locales that are supported in list formatting without having to fall back to the runtime's default locale.

语法

¥Syntax

js
Intl.ListFormat.supportedLocalesOf(locales)
Intl.ListFormat.supportedLocalesOf(locales, options)

参数

¥Parameters

locales

带有 BCP 47 语言标记的字符串,或此类字符串的数组。有关 locales 论证的一般形式和解释,请参阅 Intl 主页参数说明

options Optional

可能具有以下属性的对象:

localeMatcher

要使用的区域设置匹配算法。可能的值为 "lookup""best fit";默认为 "best fit"。有关此选项的信息,请参阅 Intl 页。

返回值

¥Return value

表示给定区域设置标记子集的字符串数组,列表格式支持这些标记,而无需回退到运行时的默认区域设置。

¥An array of strings representing a subset of the given locale tags that are supported in list formatting without having to fall back to the runtime's default locale.

示例

¥Examples

使用 supportedLocalesOf()

¥Using supportedLocalesOf()

假设运行时在列表格式中支持印度尼西亚语和德语,但不支持巴厘岛语,supportedLocalesOf 将返回印度尼西亚语和德语语言标签不变,尽管 pinyin 排序规则既不与列表格式相关,也不与印度尼西亚语一起使用,并且不太可能为印度尼西亚语提供专门的德语。 支持的。请注意此处 "lookup" 算法的规范 - "best fit" 匹配器可能会认为印度尼西亚语足以匹配巴厘岛语,因为大多数巴厘岛人也理解印度尼西亚语,因此也返回巴厘岛语语言标签。

¥Assuming a runtime that supports Indonesian and German but not Balinese in list formatting, supportedLocalesOf returns the Indonesian and German language tags unchanged, even though pinyin collation is neither relevant to list 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.

js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.ListFormat.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]

规范

Specification
ECMAScript Internationalization API Specification
# sec-Intl.ListFormat.supportedLocalesOf

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also