Intl.DisplayNames.prototype.of()
Intl.DisplayNames.prototype.of()
メソッドは、コードを受け取り、Intl.DisplayNames をインスタンス化するときに指定されたロケールとオプションに基づいて文字列を返します。
試してみましょう
構文
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 メソッドの使用
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 Internationalization API Specification # sec-Intl.DisplayNames.prototype.of |
ブラウザーの互換性
BCD tables only load in the browser