Intl.DisplayNames.prototype.resolvedOptions()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2021年4月.
resolvedOptions() は Intl.DisplayNames インスタンスのメソッドで、現在の DisplayNames オブジェクトの初期化時に計算されたロケールとスタイルの書式オプションを反映したプロパティを持つ新しいオブジェクトを返します。
構文
resolvedOptions()
引数
なし。
返値
この DisplayNames オブジェクトの初期化時に計算されたオプションを反映したプロパティを持つ新しいオブジェクトです。このオブジェクトには、記載順に以下のプロパティがあります。
locale-
実際に使用されているロケールの BCP 47 言語タグです。これは、ロケールネゴシエーションのプロセスによって決定されます。出力には、Unicode 拡張キーは記載されません。
style-
options引数でこのプロパティに指定された値です。必要に応じてデフォルト値が設定されます。値は"narrow"、"short"、"long"のいずれかです。デフォルト値は"long"です。 type-
options引数でこのプロパティに指定された値です。値は"language"、"region"、"script"、"currency"、"calendar"、"dateTimeField"のいずれかです。必須項目であるため、デフォルト値はありません。 fallback-
options引数でこのプロパティに指定された値です。"code"または"none"のどちらかです。デフォルト値は"code"です。 languageDisplay-
options引数でこのプロパティに指定された値です。"dialect"または"standard"のいずれかです。デフォルトは"dialect"です。
例
>resolvedOptions の使用
const displayNames = new Intl.DisplayNames(["de-DE"], { type: "region" });
const usedOptions = displayNames.resolvedOptions();
console.log(usedOptions.locale); // "de-DE"
console.log(usedOptions.style); // "long"
console.log(usedOptions.type); // "region"
console.log(usedOptions.fallback); // "code"
const displayNames = new Intl.DisplayNames("en", {
type: "language",
languageDisplay: "standard",
});
const usedOptions = displayNames.resolvedOptions();
console.log(usedOptions.type); // "language"
console.log(usedOptions.languageDisplay); // "standard"
仕様書
| Specification |
|---|
| ECMAScript® 2027 Internationalization API Specification> # sec-Intl.DisplayNames.prototype.resolvedOptions> |