Intl.Segmenter.supportedLocalesOf()
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));
// Expected output: Array ["id-u-co-pinyin", "de-ID"]
// (Note: the exact output may be browser-dependent)
語法
js
Intl.Segmenter.supportedLocalesOf(locales)
Intl.Segmenter.supportedLocalesOf(locales, options)
引數
locales-
一個帶有 BCP 47 語言標籤的字串,或者此類字串的陣列。關於
locales引數的一般形式和解釋,請參閱Intl主頁上的引數說明。 options可選-
一個可能具有以下屬性的物件
localeMatcher-
要使用的 locale 匹配演算法。可能的值為
"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));
// ["id-u-co-pinyin", "de-ID"]
規範
| 規範 |
|---|
| ECMAScript® 2026 國際化 API 規範 # sec-intl.segmenter.supportedlocalesof |
瀏覽器相容性
載入中…