Intl.Segmenter.prototype.resolvedOptions()
Baseline 2024Newly 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 Methode resolvedOptions()
von Instanzen des Intl.Segmenter
gibt ein neues Objekt zurück, das die Optionen widerspiegelt, die bei der Initialisierung dieses Segmenter
-Objekts berechnet wurden.
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
resolvedOptions()
Parameter
Keine.
Rückgabewert
Ein neues Objekt mit Eigenschaften, die die bei der Initialisierung dieses Segmenter
-Objekts berechneten Optionen widerspiegeln. Das Objekt hat die folgenden Eigenschaften, in der Reihenfolge ihrer Auflistung:
locale
-
Das BCP 47-Sprach-Tag für das tatsächlich verwendete Locale, bestimmt durch den Locale-Verhandlungsprozess. Kein Unicode-Erweiterungsschlüssel wird in der Ausgabe enthalten sein.
granularity
-
Der Wert, der für diese Eigenschaft im
options
-Argument angegeben wurde, wobei Standards nach Bedarf ausgefüllt werden. Es ist entweder"grapheme"
,"word"
oder"sentence"
. Der Standardwert ist"grapheme"
.
Beispiele
Grundlegende Nutzung
const spanishSegmenter = new Intl.Segmenter("es", { granularity: "sentence" });
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "sentence"
Standard-Granularität
const spanishSegmenter = new Intl.Segmenter("es");
const options = spanishSegmenter.resolvedOptions();
console.log(options.locale); // "es"
console.log(options.granularity); // "grapheme"
Fallback-Locale
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® 2025 Internationalization API Specification # sec-intl.segmenter.prototype.resolvedoptions |
Browser-Kompatibilität
BCD tables only load in the browser