JavaScript

Intl.DisplayNames.prototype.of() メソッド


編集:2023.01.09 by T.A.

[Edge]。→

Intl.DisplayNames に従い指定値を翻訳し文字列で返します。

構文
Intl.DisplayNames.of(code)
Intl.DisplayNames Intl.DisplayNames
code 値は文字列で、Intl.DisplayNamesoptionstype の指定値により異なります。
type が "language" の場合
言語コード[-文字体系][-国コード] (-variant)*

の「unicode_language_id」¶?。→言語タグ

type が "region" の場合
値は、2 文字の ISO-3166 地域コード、または 3文字の数値コード。→
type が "script" の場合
値は、ISO-15924 文字体系の 4 文字コード。→
type が "currency" の場合
値は、3 文字の ISO 4217 通貨コード。→
戻り値

文字列。

テスト
DA=new Intl.DisplayNames('ja', {type:'language'});  //日本語、タイプ:言語。
D=DA.of('en');  //英語。(enを日本語に翻訳)
	//=[string]:英語
D=DA.of('en-US');  //英語でアメリカ合衆国。
	//=[string]:英語 (アメリカ合衆国)
D=DA.of('Latn-US');  //ラテン文字でアメリカ合衆国。
	//=[string]:latn (アメリカ合衆国)。おかしい。
D=DA.of('en-Latn');  //英語でラテン文字。
	//=[string]:英語 (ラテン文字)
D=DA.of('en-Latn-US');  //英語でラテン文字でアメリカ合衆国。
	//=[string]:英語 (ラテン文字、アメリカ合衆国)
D=DA.of('root');  //?
	//=[string]:root
//↑この結果から、「unicode_language_id」の公式は有効でないと思える。

DA=new Intl.DisplayNames('ja', {type:'region'});  //日本語、タイプ:国。
D=DA.of('US');  //アメリカ合衆国。
	//=[string]:アメリカ合衆国
D=DA.of('JP');  //日本国。
	//=[string]:日本

DA=new Intl.DisplayNames('ja', {type:'script'});  //日本語、タイプ:文字体系。
D=DA.of('Jpan');  //日本文字。
	//=[string]:日本語の文字
D=DA.of('Cyrl');  //キリル文字。
	//=[string]:キリル文字

DA=new Intl.DisplayNames('ja', {type:'currency'});  //日本語、タイプ:通貨。
D=DA.of('JPY');  //円。
	//=[string]:日本円
D=DA.of('CAD');  //カナダ ドル。
	//=[string]:カナダ ドル

Intl.DisplayNames()


テスト