首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Intl.Collator.supportedLocalesOf

Intl.Collator.supportedLocalesOf()方法返回一个数组,其中包含在归类中支持的所提供语言环境的数组,而不必回退到运行时的默认语言环境。

语法

代码语言:javascript
复制
Intl.Collator.supportedLocalesOf(locales[, options])

参数

locales一个带有BCP 47语言标签的字符串或这种字符串的数组。有关locales参数的一般形式,请参阅Intl页面。

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

localeMatcher要使用的语言环境匹配算法。可能的值是"lookup""best fit"; 默认是"best fit"。有关此选项的信息,请参阅Intl页面。

返回值

一个字符串数组,表示给定区域设置标记,而不必回退到运行时的默认语言环境。

描述

返回一个数组,其中包含所提供locales语言标签的一个子集。标记值发生匹配的对象会被返回,因此它不必回退到默认语言环境。

例子

使用supportedLocalesOf

假设运行时支持对印尼语和德语,但不是支持巴厘岛方言。虽然印尼语中不使用拼音来校对,也不支持“印尼版德语”,但是supportedLocalesOf 会返回德语和印尼语的标签。注意这里的 "lookup" 算法,"最佳匹配" 会出现匹配“印尼语”和“巴厘岛”方言的情况, 因为大多数巴厘岛语言与印尼语互通, 因此也会返回巴厘岛方言的语言标签。

代码语言:javascript
复制
var locales = ['ban', 'id-u-co-pinyin', 'de-ID'];
var options = { localeMatcher: 'lookup' };
console.log(Intl.Collator.supportedLocalesOf(locales, options).join(', '));
// → "id-u-co-pinyin, de-ID"

规范

Specification

Status

Comment

ECMAScript Internationalization API 1.0 (ECMA-402)The definition of 'Intl.Collator.supportedLocalesOf' in that specification.

Standard

Initial definition.

ECMAScript Internationalization API 2.0 (ECMA-402)The definition of 'Intl.Collator.supportedLocalesOf' in that specification.

Standard

?

ECMAScript Internationalization API 4.0 (ECMA-402)The definition of 'Intl.Collator.supportedLocalesOf' in that specification.

Draft

?

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

24

(Yes)

29 (29)

11

15

No support

Feature

Android

Chrome for Android

Edge

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

26

(Yes)

56.0 (56)

No support

No support

No support

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com