このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

Intl.Segmenter.prototype.resolvedOptions()

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.

resolvedOptions()Intl.Segmenter インスタンスンのメソッドで、この Segmenter オブジェクトの初期化中に計算されたオプションを反映したプロパティを持つ新しいオブジェクトを返します。

試してみましょう

const segmenter = new Intl.Segmenter("fr-FR");
const options = segmenter.resolvedOptions();

console.log(options.locale);
// 予想される結果: "fr-FR"

console.log(options.granularity);
// 予想される結果: "grapheme"

構文

js
resolvedOptions()

引数

なし。

返値

この Segmenter オブジェクトの初期化時に計算されたオプションを反映したプロパティを持つ新しいオブジェクトです。このオブジェクトには、記載順に次のプロパティがあります。

locale

実際に使用されるロケールの BCP 47 言語タグです。これは、ロケールネゴシエーションの処理によって決定されます。出力には、Unicode 拡張キーは含まれません。

granularity

options 引数でこのプロパティに指定された値です。必要に応じてデフォルト値が設定されます。値は "grapheme""word""sentence" のいずれかです。デフォルトは "grapheme" です。

基本的な使い方

js
const spanishSegmenter = new Intl.Segmenter("es", { granularity: "sentence" });
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "sentence"

デフォルトの粒度

js
const spanishSegmenter = new Intl.Segmenter("es");
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "grapheme"

locale のフォールバック

js
const banSegmenter = new Intl.Segmenter("ban");
const options = banSegmenter.resolvedOptions();
console.log(options.locale);
// Balinese ロケールに対応しておらず、
// デフォルトのロケールが French であるランタイムでは、"fr"
console.log(options.granularity); // "grapheme"

仕様書

Specification
ECMAScript® 2027 Internationalization API Specification
# sec-intl.segmenter.prototype.resolvedoptions

ブラウザーの互換性