Intl【国際化API名前空間】オブジェクト

メモ

概要

  • 国際化対応APIの名前空間 オブジェクト

ロケール

外部リンク

プロパティ一覧

プロパティ備考
Intl.Collator【国際化文字列比較】コンストラクタ
Intl.DateTimeFormat 【国際化日時フォーマット】コンストラクタ
Intl.DisplayNames 【国際化表示名】コンストラクタ
Intl.ListFormat 【国際化リスト要素フォーマット】コンストラクタ
Intl.Locale 【Unicode ロケール識別子】コンストラクタ
Intl.NumberFormat 【国際化数値フォーマット】コンストラクタ
Intl.PluralRules 【複数形ルール】コンストラクタ
Intl.RelativeTimeFormat 【国際化相対時間フォーマット】コンストラクタ
Intl.Segmenter 【国際化テキスト区切り】コンストラクタ

メソッド一覧

メソッド備考
Intl.getCanonicalLocales ( locales ) 標準ロケール名取得
Intl.supportedValuesOf ( key ) 実装サポート値取得

Intl.getCanonicalLocales【標準ロケール名取得】

メモ

概要

  • 言語タグを正規化

関連

外部リンク

構文

Intl.getCanonicalLocales( locales ) 

BCP 47に正規化した言語タグの配列 (重複は削除)
locales言語タグ文字列 または その配列

TypeError 言語タグが文字列以外
RangeError 不正な言語タグ

console.log( Intl.getCanonicalLocales('ja') );
// 出力:['ja']
console.log(Intl.getCanonicalLocales('ja-jp'));
// 出力:['ja-JP']

console.log(Intl.getCanonicalLocales( ['ja-jp', 'en-us', 'en-gb', 'JA-JP', 'EN-US', 'EN-GB']) );
// 出力:(3) ['ja-JP', 'en-US', 'en-GB']

try {
  console.log( Intl.getCanonicalLocales(null) );
} catch(e) {
  console.log(e); // 例外:TypeError: Cannot convert undefined or null to object
}
try {
  console.log( Intl.getCanonicalLocales('ja_JP') );
} catch(e) {
  console.log(e); // 例外:RangeError: Incorrect locale information provided
}

Intl.supportedValuesOf【実装サポート値取得】

メモ

概要

  • 実装のサポート値を取得

関連

外部リンク

  • ECMA-402 (英語)
    Intl.supportedValuesOf ( key )
    ES2023 Intl (10) ES2022 Intl (9) ES2021 Intl (8)

構文

Intl.supportedValuesOf ( key ) 

サポート値のリスト (昇順にソート)
keyキー
RangeError key (キー)が無効
key (キー)備考
'calendar'
'collation'比較方法
'currency'通貨
'numberingSystem'数値システム
'timeZone'タイムゾーン
'unit'単位

console.log( Intl.supportedValuesOf('calendar') );
// 出力例:
// (18) ['buddhist', 'chinese', 'coptic', 'dangi', 'ethioaa', 'ethiopic', 'gregory', 'hebrew', 'indian', 'islamic', 'islamic-civil', 'islamic-rgsa', 'islamic-tbla', 'islamic-umalqura', 'iso8601', 'japanese', 'persian', 'roc']

console.log( Intl.supportedValuesOf('collation') );
// 出力例:
// (10) ['compat', 'emoji', 'eor', 'phonebk', 'pinyin', 'searchjl', 'stroke', 'trad', 'unihan', 'zhuyin']

console.log( Intl.supportedValuesOf('currency') );
// 出力例:
// (159) [ … 'AUD' … 'CAD' … 'CHF' … 'EUR' … 'GBP' … 'JPY' … 'NZD' … 'USD' … 'ZAR' … ]

console.log( Intl.supportedValuesOf('numberingSystem') );
// 出力例:
// (69) ['adlm', 'ahom', 'arab', 'arabext', 'bali', 'beng', 'bhks', 'brah', 'cakm', 'cham', 'deva', 'diak', 'fullwide', 'gong', 'gonm', 'gujr', 'guru', 'hanidec', 'hmng', 'hmnp', 'java', 'kali', 'kawi', 'khmr', 'knda', 'lana', 'lanatham', 'laoo', 'latn', 'lepc', 'limb', 'mathbold', 'mathdbl', 'mathmono', 'mathsanb', 'mathsans', 'mlym', 'modi', 'mong', 'mroo', 'mtei', 'mymr', 'mymrshan', 'mymrtlng', 'nagm', 'newa', 'nkoo', 'olck', 'orya', 'osma', 'rohg', 'saur', 'segment', 'shrd', 'sind', 'sinh', 'sora', 'sund', 'takr', 'talu', 'tamldec', 'telu', 'thai', 'tibt', 'tirh', 'tnsa', 'vaii', 'wara', 'wcho']

console.log( Intl.supportedValuesOf('timeZone') );
// 出力例:
// (429) [
// …
// (抜粋)
// 'Africa/Cairo',
// 'Africa/Kinshasa',
// 'Africa/Luanda',
// 'Africa/Nairobi',
// 'America/Los_Angeles',
// 'America/New_York',
// 'America/Whitehorse',
// 'Antarctica/Syowa',
// 'Arctic/Longyearbyen',
// 'Asia/Tokyo',
// 'Atlantic/St_Helena',
// 'Australia/Melbourne',
// 'Australia/Sydney',
// 'Europe/Berlin',
// 'Europe/London',
// 'Europe/Paris',
// 'Indian/Christmas',
// 'Pacific/Guam',
// 'Pacific/Honolulu',
// 'Pacific/Saipan',
// …
// ]

console.log( Intl.supportedValuesOf('unit') );
// 出力例:
// (45) ['acre', 'bit', 'byte', 'celsius', 'centimeter', 'day', 'degree', 'fahrenheit', 'fluid-ounce', 'foot', 'gallon', 'gigabit', 'gigabyte', 'gram', 'hectare', 'hour', 'inch', 'kilobit', 'kilobyte', 'kilogram', 'kilometer', 'liter', 'megabit', 'megabyte', 'meter', 'microsecond', 'mile', 'mile-scandinavian', 'milliliter', 'millimeter', 'millisecond', 'minute', 'month', 'nanosecond', 'ounce', 'percent', 'petabyte', 'pound', 'second', 'stone', 'terabit', 'terabyte', 'week', 'yard', 'year']

try {
  console.log( Intl.supportedValuesOf('NG') );
} catch(e) {
  console.log(e); // 例外:RangeError: Invalid key : NG
}