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.

Die resolvedOptions()-Methode von Instanzen des Intl.Segmenter gibt ein neues Objekt zurück, das Eigenschaften enthält, die die während der Initialisierung dieses Segmenter-Objekts berechneten Optionen widerspiegeln.

Probieren Sie es aus

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"

Syntax

js
resolvedOptions()

Parameter

Keine.

Rückgabewert

Ein neues Objekt mit Eigenschaften, die die während der Initialisierung dieses Segmenter-Objekts berechneten Optionen widerspiegeln. Das Objekt hat folgende Eigenschaften, in der Reihenfolge, wie sie aufgelistet sind:

locale

Das BCP 47-Sprach-Tag für die tatsächlich verwendete Sprache, bestimmt durch den Sprach-Aushandlungsprozess. Kein Unicode-Erweiterungsschlüssel wird in der Ausgabe enthalten sein.

granularity

Der Wert, der für diese Eigenschaft im options-Argument angegeben wurde, wobei nach Bedarf Standardwerte eingefügt werden. Es ist entweder "grapheme", "word" oder "sentence". Der Standardwert ist "grapheme".

Beispiele

Grundlegende Nutzung

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

Standardmäßige Granularität

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

Fallback-Sprache

js
const banSegmenter = new Intl.Segmenter("ban");
const options = banSegmenter.resolvedOptions();
console.log(options.locale);
// "fr" on a runtime where the Balinese locale
// is not supported and French is the default locale
console.log(options.granularity); // "grapheme"

Spezifikationen

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

Browser-Kompatibilität