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
によって変わります。- type が "region" である場合、コードは ISO-3166 地域の 2 文字コードまたは three digits UN M49 Geographic Regions である必要があります。
- type が "script" である場合、コードは ISO-15924 文字体系の 4 文字コードである必要があります。
- type が "language" である場合、コードは languageCode ["-" scriptCode] ["-" regionCode ] *("-" variant ) の形である必要があり、これは UTS 35's Unicode Language and Locale Identifiers grammar の unicode_language_id の構文です。 languageCode は 2 文字の ISO 639-1 言語コードまたは 3 文字の ISO 639-2 言語コードです。
- type が "currency" である場合、コードは 3 文字の ISO 4217 通貨コードである必要があります。
返値
その言語における書式化された文字列です。
例
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 |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
of |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.