GT ClassMethodsLocales

getLocaleProperties

GT の getLocaleProperties メソッドのAPIリファレンス

概要

getLocaleProperties メソッドはロケールコードに対応する包括的なプロパティを取得し、 表示名、地域コード、スクリプト情報、emoji フラグなどの詳細情報を提供します。 国際化対応のリッチなユーザーインターフェースを構築するために必要なデータをすべて備えた完全な LocaleProperties オブジェクトを返します。

const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'es'
});

const props = gt.getLocaleProperties('fr-CA');
console.log(props.name); // "フランス語 (カナダ)"
console.log(props.nativeName); // "français (Canada)"
console.log(props.emoji); // "🇨🇦"

リファレンス

パラメータ

Prop

Type

パラメータの説明

パラメータ説明
localeプロパティを取得する対象を示す BCP-47 のロケールコード。指定がない場合は、このインスタンスの targetLocale を使用します

返り値

LocaleProperties - すべてのロケール情報を含む包括的なオブジェクト:

  • code: 標準化されたロケールコード
  • name: ソースロケールでの表示名称
  • nativeName: ネイティブの表示名称
  • languageCode, languageName, nativeLanguageName: 言語情報
  • regionCode, regionName, nativeRegionName: 地域情報
  • scriptCode, scriptName, nativeScriptName: スクリプト情報
  • maximizedCode, minimizedCode: 正準形式
  • nameWithRegionCode, nativeNameWithRegionCode: 組み合わせ表示形式
  • emoji: 国旗または代表的なemoji

例外

  • Error - locale が指定されておらず、かつインスタンスに targetLocale が設定されていない場合

基本的な使い方

const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'fr'
});

// 対象ロケールのプロパティを取得
const props = gt.getLocaleProperties();
console.log(props.name); // "French (France)"
console.log(props.nativeName); // "français (France)"
console.log(props.languageCode); // "fr"
console.log(props.regionCode); // "FR"
console.log(props.emoji); // "🇫🇷"

// 他のロケールのプロパティを取得
const germanProps = gt.getLocaleProperties('de-AT');
console.log(germanProps.name); // "Austrian German"
console.log(germanProps.nativeName); // "Österreichisches Deutsch"
console.log(germanProps.regionName); // "Austria"
console.log(germanProps.nativeRegionName); // "Österreich"

注意

  • すべての表示名は、インスタンスの sourceLocale 設定に従います
  • カスタムのマッピングプロパティは、標準の Intl APIs(国際化 API)より優先されます

次のステップ

このガイドはどうでしたか?

getLocaleProperties