Intl.PluralRules

Baseline Widely available *

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2019.

* Some parts of this feature may have varying levels of support.

Intl.PluralRules 对象是用于复数敏感的格式化和复数相关的语言规则。

构造函数

Intl.PluralRules()

创建一个新的 Intl.PluralRules 对象。

静态方法

Intl.PluralRules.supportedLocalesOf()

返回一个数组,其中包含提供的区域(locale)中被运行时所支持的,而不必回退到运行时的默认区域。

实例方法

Intl.PluralRules.prototype.resolvedOptions()

返回一个新的对象,其属性反映了在对象初始化期间计算所得的区域和一系列选项。

Intl.PluralRules.prototype.select()

返回一个字符串,指示用于区域敏感的格式化的复数类别。

Intl.PluralRules.prototype.selectRange()

此方法接收两个值并返回一个字符串,指示用于区域敏感的格式化的复数类别。

示例

使用 locales

此示例显示本地化复数类别的一些值。为了获得应用程序用户界面中使用的语言格式,请确保使用 locales 参数指定了语言(可能还有一些回退语言):

js
// 阿拉伯语有不同的复数类别

new Intl.PluralRules("ar-EG").select(0);
// → 'zero'
new Intl.PluralRules("ar-EG").select(1);
// → 'one'
new Intl.PluralRules("ar-EG").select(2);
// → 'two'
new Intl.PluralRules("ar-EG").select(6);
// → 'few'
new Intl.PluralRules("ar-EG").select(18);
// → 'many'

规范

Specification
ECMAScript® 2025 Internationalization API Specification
# pluralrules-objects

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
PluralRules
PluralRules() constructor
options parameter
options.roundingIncrement parameter
options.roundingMode parameter
options.roundingPriority parameter
options.trailingZeroDisplay parameter
Experimental
resolvedOptions
select
selectRange
supportedLocalesOf

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Partial support
Partial support
No support
No support
Experimental. Expect behavior to change in the future.
See implementation notes.
Has more compatibility info.

参见