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.

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

試してみましょう

const segmenter1 = new Intl.Segmenter("fr-FR");
const options1 = segmenter1.resolvedOptions();

console.log(options1.locale);
// Expected output: "fr-FR"

console.log(options1.granularity);
// Expected output: "grapheme"

構文

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

ブラウザーの互換性

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
resolvedOptions

Legend

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

Full support
Full support