Intl.DisplayNames
Intl.DisplayNames オブジェクトは、言語、地域、文字体系の表示名の一貫した翻訳を可能にします。
対応ブラウザ
| 機能 | デスクトップ | モバイル | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 81 | 81 | 86 | 14.1 | 81 | 14.5 | |
| ビルトインオブジェクト | ||||||
| Intl.DisplayNames() コンストラクターは、 Intl.DisplayNames オブジェクトを生成します。 | 81 | 81 | 86 | 14.1 | 81 | 14.5 |
| Intl.DisplayNames.prototype.of() メソッドは、コードを受け取り、Intl.DisplayNames をインスタンス化するときに指定されたロケールとオプションに基づいて文字列を返します。 | 81 | 81 | 86 | 14.1 | 81 | 14.5 |
| Intl.DisplayNames.prototype.resolvedOptions() メソッドは、現在の Intl.DisplayNames オブジェクトの初期化時に計算されたロケールとスタイルの書式オプションを反映したプロパティを持つ新しいオブジェクトを返します。 | 81 | 81 | 86 | 14.1 | 81 | 14.5 |
| Intl.DisplayNames.supportedLocalesOf() メソッドは、指定されたロケールのうち、ランタイムの既定のロケールで代替せずに表示名に対応しているものの配列を返します。 | 81 | 81 | 86 | 14.1 | 81 | 14.5 |
基本構文
JAVASCRIPT
const names = new Intl.DisplayNames(['ja'], { type: 'language' });
names.of('en'); // 'English'
names.of('zh-Hans'); // 'Chinese (Simplified)'
const regions = new Intl.DisplayNames(['ja'], { type: 'region' });
regions.of('US'); // 'United States' ライブデモ
実務での使いどころ
-
Intl.DisplayNames の活用
Intl.DisplayNames オブジェクトは、言語、地域、文字体系の表示名の一貫した翻訳を可能にします。
注意点
- 特になし。すべての主要ブラウザで安定して動作する。
アクセシビリティ
- JavaScript による動的更新時は、aria-live リージョンで変更をスクリーンリーダーに通知する。