Intl.Segmenter.prototype.resolvedOptions()

Intl.Segmenter.prototype.resolvedOptions() メソッドは、この Intl.Segmenter オブジェクトの初期化時に計算されたロケールおよび粒度のオプションを反映したプロパティを持つ新しいオブジェクトを返します。

試してみましょう

構文

js
resolvedOptions();

引数

なし。

返値

与えられた Intl.Segmenter オブジェクトの初期化時に計算されたロケールおよび照合順序のオプションを反映したプロパティを持つ新しいオブジェクトです。

解説

生成されたオブジェクトは以下のプロパティを持ちます。

locale

実際に使用されるロケールの BCP 47 言語タグ。初期化のための BCP 47 言語タグに Unicode 拡張値が含まれていた場合、要求され、このロケールに対応しているキーと値のペアが locale に含まれる。

granularity

オプション引数でこのプロパティに指定された値、またはデフォルト値。

基本的な使い方

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

デフォルトの granularity

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 Internationalization API Specification
# sec-intl.segmenter.prototype.resolvedoptions

ブラウザーの互換性

BCD tables only load in the browser