Intl.Locale.prototype.getCollations()
Intl.Locale
实例的 getCollations()
方法返回此语言环境的一个或多个 排序规则类型 的列表。
¥The getCollations()
method of Intl.Locale
instances returns a list of one or more collation types for this locale.
注意:在某些浏览器的某些版本中,此方法被实现为名为
collations
的访问器属性。但是,由于每次访问时都会返回一个新数组,因此现在将其实现为一种方法,以防止出现locale.collations === locale.collations
返回false
的情况。检查 浏览器兼容性表 了解详细信息。¥Note: In some versions of some browsers, this method was implemented as an accessor property called
collations
. However, because it returns a new array on each access, it is now implemented as a method to prevent the situation oflocale.collations === locale.collations
returningfalse
. Check the browser compatibility table for details.
语法
参数
返回值
¥Return value
表示 Locale
常用的所有排序规则类型的字符串数组,按字母顺序排序,始终排除 standard
和 search
值。如果 Locale
已有 collation
,则返回的数组包含该单个值。
¥An array of strings representing all collation types commonly used for the Locale
, sorted in alphabetical order, with the standard
and search
values always excluded. If the Locale
already has a collation
, then the returned array contains that single value.
下面是受支持的排序规则类型的列表,改编自 Unicode 排序规则规范。
¥Below is a list of the supported collation types, adapted from the Unicode collation specification.
支持的排序规则类型
¥Supported collation types
big5han
-
拉丁文拼音排序,中日韩字符 big5 字符集排序(中文)
警告:
big5han
排序规则类型已弃用,在 Firefox、Chrome 或 Edge 中不可用。¥Warning: The
big5han
collation type is deprecated, not available in Firefox, Chrome or Edge. compat
-
以前版本的排序,用于兼容性(阿拉伯语)
dict
-
字典式排序(僧伽罗语)
direct
-
二进制码点顺序
警告:
direct
排序规则类型已被弃用。不使用。¥Warning: The
direct
collation type has been deprecated. Do not use. ducet
-
默认 Unicode 排序规则元素表顺序
警告:
ducet
排序规则类型不可用于 Web。请改用不带排序规则类型说明符的und
语言环境。und
是最接近ducet
的排序规则。¥Warning: The
ducet
collation type is not available to the Web. Use theund
locale without a collation type specifier instead.und
is the collation that is the closest toducet
. emoji
-
表情符号字符的推荐排序(针对
und
语言环境) eor
-
欧洲订购规则(针对
und
语言环境) gb2312
-
拉丁文拼音排序,中日韩字符 GB2312han 字符集排序(中文)
警告:
gb2312
排序规则类型已弃用,在 Firefox、Chrome 或 Edge 中不可用。¥Warning: The
gb2312
collation type is deprecated, not available in Firefox, Chrome or Edge. phonebk
-
调用簿样式排序(德语)
phonetic
-
语音排序(根据发音排序;林加拉语)
pinyin
-
拉丁文和 CJK 字符的拼音顺序(适用于中文)
reformed
-
改革排序(以前用于瑞典语)
警告:不要明确使用。这是瑞典 其排序规则命名与其他语言不同 默认排序的旧名称。由于这是默认值,因此请求
sv
而不是请求sv-u-co-reformed
。¥Warning: Do not use explicitly. This is the old name for the default ordering for Swedish whose collation naming used to differ from other languages. Since this was the default, request
sv
instead of requestingsv-u-co-reformed
. search
-
用于字符串搜索的特殊排序规则类型
警告:不要用作排序规则类型,因为在
Intl.Collator
中,此排序规则是通过usage
选项的"search"
值激活的。目前没有用于子字符串搜索的 API,因此目前仅适用于通过尝试将键与每个列表项进行全字符串匹配来过滤字符串列表。¥Warning: Do not use as a collation type, since in
Intl.Collator
, this collation is activated via the"search"
value for theusage
option. There is currently no API for substring search, so this is currently only good for filtering a list of strings by trying a full-string match of the key against each list item. searchjl
-
用于韩语声母搜索的特殊排序类型
警告:此排序规则不用于排序,尽管它是通过使用
"sort"
(而不是使用"search"
)实例化的Intl.Collator
提供的。¥Warning: This collation is not for sorting, even though it is made available through
Intl.Collator
instantiated with usage"sort"
as opposed to usage"search"
. standard
-
每种语言的默认顺序,中文除外(以及之前的瑞典语)
警告:不要明确使用。一般来说,没有必要明确指定这一点,并且由于过去瑞典语的含义不同,为瑞典语指定这一点是有问题的。
¥Warning: Do not use explicitly. In general, it's unnecessary to specify this explicitly and specifying this for Swedish is problematic due to the different meaning for Swedish in the past.
stroke
-
拉丁文的拼音顺序,CJK 字符的笔画顺序(对于中文)
trad
-
传统风格的排序(例如西班牙语)
unihan
-
汉字的部首笔画顺序(适用于中文、日文和韩文)。中文的拉丁文拼音顺序。
注意:
unihan
排序规则类型在 Chrome 或 Edge 中不可用。¥Note: The
unihan
collation type is not available in Chrome or Edge. zhuyin
-
拉丁语拼音顺序、波波莫福语和中日韩字符注音顺序(适用于中文)
示例
获取支持的排序规则类型
¥Obtaining supported collation types
如果 Locale
对象还没有 collation
,则 getCollations()
列出给定 Locale
的所有常用排序规则类型。有关显式设置 collation
的示例,请参阅 collation
个例子。
¥If the Locale
object doesn't have a collation
already, getCollations()
lists all commonly-used collation types for the given Locale
. For examples of explicitly setting a collation
, see collation
examples.
const locale = new Intl.Locale("zh");
console.log(locale.getCollations()); // ["pinyin", "stroke", "zhuyin", "emoji", "eor"]
规范
Specification |
---|
Intl Locale Info Proposal # sec-Intl.Locale.prototype.getCollations |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also