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 locales1 = ["ban", "id-u-co-pinyin", "de-ID"];
const options1 = { localeMatcher: "lookup", granularity: "string" };

console.log(Intl.Segmenter.supportedLocalesOf(locales1, options1));
// Expected output: Array ["id-u-co-pinyin", "de-ID"]
// (Note: the exact output may be browser-dependent)

構文

js
supportedLocalesOf(locales);
supportedLocalesOf(locales, options);

引数

locales

BCP 47 の言語タグを持つ文字列、またはそのような文字列の配列。引数 locales の一般的な形式と解釈については、Intl のページを参照してください。

options 省略可

以下のプロパティを持つ可能性があるオブジェクト。

localeMatcher

使用するロケールマッチングアルゴリズム。使用可能な値は "lookup" および "best fit" で、デフォルトは "best fit" です。このオプションの詳細については、Intl のページを参照ください。

返値

指定したロケールタグのサブセットを表す文字列の配列で、ランタイムのデフォルトロケールにフォールバックすることなくセグメンテーションでサポートされるものです。

supportedLocalesOf() の使用方法

実行環境がリスト形式でインドネシア語とドイツ語をサポートし、バリ語をサポートしないと仮定すると、supportedLocalesOf はインドネシア語とドイツ語の言語タグを変更せずに返します。pinyin の照合順序はインドネシア語のセグメンテーションに関係なく、またインドネシア語に特化したドイツ語はないためサポートされません。ここで "lookup" アルゴリズムの仕様に注意してください。"best fit" マッチでは、バリ島のほとんどの住民がインドネシア語を理解するため、インドネシア語がバリ島の言語に適切に一致すると判断し、バリ島の言語タグも返すことがあります。

js
const locales = ["ban", "id-u-co-pinyin", "de-ID"];
const options = { localeMatcher: "lookup" };
console.log(Intl.Segmenter.supportedLocalesOf(locales, options).join(", "));
// → "id-u-co-pinyin, de-ID"

仕様書

Specification
ECMAScript® 2025 Internationalization API Specification
# sec-intl.segmenter.supportedlocalesof

ブラウザーの互換性

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
supportedLocalesOf

Legend

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

Full support
Full support