Intl.PluralRules.prototype.selectRange()

Intl.PluralRules 实例的 selectRange() 方法接收两个值并返回一个字符串,指示使用哪个复数规则来对指示范围进行区域设置感知格式设置。

¥The selectRange() method of Intl.PluralRules instances receives two values and returns a string indicating which plural rule to use for locale-aware formatting of the indicated range.

语法

¥Syntax

js
selectRange(startRange, endRange)

参数

¥Parameters

startRange

代表范围开始的数字。

endRange

代表范围结束的数字。

返回值

¥Return value

表示指定范围的复数类别的字符串。这可以是 zeroonetwofewmanyother 之一,与 LDML 语言复数规则 中指定的本地化语言环境相关。

¥A string representing the pluralization category of the specified range. This can be one of zero, one, two, few, many or other, that are relevant for the locale whose localization is specified in LDML Language Plural Rules.

描述

¥Description

此函数根据 Intl.PluralRules 对象的区域设置和格式选项选择复数类别。

¥This function selects a pluralization category according to the locale and formatting options of an Intl.PluralRules object.

从概念上讲,该行为与获取单个基数或序数的复数规则相同。语言具有一种或多种用于描述范围的形式,并且在给定提供的区域设置和格式选项的情况下,此方法返回适当的形式。英语中只有一种复数形式,例如 "1–10 个苹果",该方法将返回 other。其他语言可以有多种形式。

¥Conceptually the behavior is the same as getting plural rules for a single cardinal or ordinal number. Languages have one or more forms for describing ranges, and this method returns the appropriate form given the supplied locale and formatting options. In English there is only one plural form, such as "1–10 apples", and the method will return other. Other languages can have many forms.

示例

¥Examples

使用 selectRange()

¥Using selectRange()

js
new Intl.PluralRules("sl").selectRange(102, 201); // 'few'

new Intl.PluralRules("pt").selectRange(102, 102); // 'other'

规范

Specification
ECMAScript Internationalization API Specification
# sec-intl.pluralrules.prototype.selectrange

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also