Intl.Segmenter.supportedLocalesOf()
Baseline
2024
Newly available
Since April 2024, this feature works across the latest devices and browser versions. This feature might not work in older devices or browsers.
Intl.Segmenter.supportedLocalesOf() 静的メソッドは、指定したロケールのうち、ランタイムのデフォルトロケールに代替されることなく対応しているものを含む配列を返します。
試してみましょう
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup", granularity: "string" };
console.log(Intl.Segmenter.supportedLocalesOf(locales, options));
// 予想される結果: Array ["id-u-co-pinyin", "de-ID"]
// (注:実際の表示はブラウザーによって異なる場合があります)
構文
Intl.Segmenter.supportedLocalesOf(locales)
Intl.Segmenter.supportedLocalesOf(locales, options)
引数
locales-
BCP 47 言語タグの文字列、またはそのような文字列の配列です。
locales引数の一般的な形と解釈については、Intlメインページにある引数の説明を参照してください。 options省略可-
以下のプロパティを持つ可能性があるオブジェクト。
localeMatcher-
使用するロケール照合アルゴリズム。使用可能な値は
"lookup"および"best fit"です。デフォルト値は"best fit"です。このオプションの詳細については、Intl のページを参照してください。
返値
ランタイムのデフォルトロケールに代替されることなく、分割処理で対応している、指定されたロケールタグのサブセットを表す文字列の配列です。
例
>supportedLocalesOf() の使用方法
実行環境がリスト形式でインドネシア語とドイツ語に対応しており、バリ語に対応していないと仮定すると、supportedLocalesOf はインドネシア語とドイツ語の言語タグを変更せずに返します。pinyin の照合順序はインドネシア語の分割処理と関係なく、またインドネシア語に特化したドイツ語はないため対応しません。ここで "lookup" アルゴリズムの仕様に注意してください。"best fit" の照合では、バリ島のほとんどの住民がインドネシア語を理解するため、インドネシア語がバリ島の言語に適切に一致すると判断し、バリ島の言語タグも返すことがあります。
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.Segmenter.supportedLocalesOf(locales, options));
// ["id-u-co-pinyin", "de-ID"]
仕様書
| Specification |
|---|
| ECMAScript® 2027 Internationalization API Specification> # sec-intl.segmenter.supportedlocalesof> |