Intl.PluralRules.select()
Baseline
広く利用可能
この機能は広く実装されており、多くのバージョンの端末やブラウザーで動作します。2019年9月以降、すべてのブラウザーで利用可能です。
Intl.PluralRules.prototype.select() メソッドは、ロケールを考慮した書式設定に使用する複数形ルールを示す文字列を返します。
試してみましょう
console.log(new Intl.PluralRules("ar-EG").select(0));
// 予想される結果: "zero"
console.log(new Intl.PluralRules("ar-EG").select(5));
// 予想される結果: "few"
console.log(new Intl.PluralRules("ar-EG").select(55));
// 予想される結果: "many"
console.log(new Intl.PluralRules("en").select(0));
// 予想される結果: "other"
構文
js
select(number);
引数
number-
複数のルールを取得するための数値です。
返値
数字の複数形のカテゴリーを表す文字列で、 zero, one, two, few, many, other のいずれかになります。
解説
この関数は、 Intl.PluralRules オブジェクトのロケールや書式オプションに応じて、複数形のカテゴリーを選択します。
例
>select() の使用
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'
仕様書
| 仕様書 |
|---|
| ECMAScript® 2027 Internationalization API Specification> # sec-intl.pluralrules.prototype.select> |