Intl.DisplayNames() コンストラクター
Intl.DisplayNames()
コンストラクターは、言語、地域、文字体系の表示名の一貫した翻訳を可能にする Intl.DisplayNames
オブジェクトを生成します。
試してみましょう
構文
new Intl.DisplayNames()
new Intl.DisplayNames(locales)
new Intl.DisplayNames(locales, options)
引数
locales
省略可-
BCP 47 言語タグの文字列、または、そのような文字列の配列です。
locales
引数の一般的な形式と解釈は、 Intl のページをご覧ください。次の Unicode 拡張キーが利用できます。nu
-
使用する数値書式です。 "
arab
", "arabext
", "bali
", "beng
", "deva
", "fullwide
", "gujr
", "guru
", "hanidec
", "khmr
", "knda
", "laoo
", "latn
", "limb
", "mlym
", "mong
", "mymr
", "orya
", "tamldec
", "telu
", "thai
", "tibt
" です。
options
省略可-
以下のプロパティの一部またはすべてを持つオブジェクトです。
localeMatcher
-
使用するロケール照合アルゴリズムです。利用可能な値は、 "
lookup
" と "best fit
" です。既定値は "best fit
" です。このオプションについての情報は、 Intl ページを参照してください。 style
-
使用する書式化スタイルです。既定値は "
long
" です。- "
narrow
" - "
short
" - "
long
"
- "
type
-
使用する種類です。
- "
language
" - "
region
" - "
script
" - "
currency
"
- "
fallback
-
使用する代替法です。既定値は "
code
" です。- "
code
" - "
none
"
- "
例
基本的な使用法
ロケールを指定しない基本的な使用法では、既定のロケールと既定のオプションで書式化された文字列が返されます。
console.log((new Intl.DisplayNames([], {type: 'language'})).of('US'));
// 期待される出力: 'us'
仕様書
Specification |
---|
ECMAScript Internationalization API Specification # sec-intl-displaynames-constructor |
ブラウザーの互換性
BCD tables only load in the browser