Intl.DisplayNames.prototype.of()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since April 2021.

Intl.DisplayNames.prototype.of() メソッドは、コードを受け取り、Intl.DisplayNames をインスタンス化するときに指定されたロケールとオプションに基づいて文字列を返します。

試してみましょう

const regionNamesInEnglish = new Intl.DisplayNames(['en'], { type: 'region' });
const regionNamesInTraditionalChinese = new Intl.DisplayNames(['zh-Hant'], {
  type: 'region',
});

console.log(regionNamesInEnglish.of('US'));
// Expected output: "United States"

console.log(regionNamesInTraditionalChinese.of('US'));
// Expected output: "美國"

構文

js
of(code);

引数

code

与える code は、 type によって変わります。

返値

その言語における書式化された文字列です。

of メソッドの使用

js
let regionNames = new Intl.DisplayNames(["en"], { type: "region" });
regionNames.of("419"); // "Latin America"

let languageNames = new Intl.DisplayNames(["en"], { type: "language" });
languageNames.of("fr"); // "French"

let currencyNames = new Intl.DisplayNames(["en"], { type: "currency" });
currencyNames.of("EUR"); // "Euro"

仕様書

Specification
ECMAScript® 2025 Internationalization API Specification
# sec-Intl.DisplayNames.prototype.of

ブラウザーの互換性

BCD tables only load in the browser

関連情報