GT ClassMethodsLocales

getLocaleName

API reference for the GT getLocaleName method

Overview

The getLocaleName method retrieves the display name of a locale code using the Intl.DisplayNames API. It returns a human-readable name for any valid BCP-47 locale code, localised according to the instance’s source locale.

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

const name = gt.getLocaleName('fr-CA');
console.log(name); // "French (Canada)"

Reference

Parameters

Prop

Type

Parameters description

ParameterDescription
localeBCP-47 locale code for which to retrieve the display name. If not provided, uses the instance’s targetLocale.

Returns

string - The localised display name of the locale.

Throws

  • Error — if no locale is provided and the instance has no targetLocale configured

Behaviour

Display language

The display name is localised according to:

  1. Instance’s sourceLocale (if configured)
  2. Library default locale (‘en’)

Custom Mapping Integration

  • Custom locale mappings are checked first
  • If a custom name is defined, it takes precedence
  • Falls back to Intl.DisplayNames for standard BCP‑47 codes

Examples

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

// Get the name for the target locale
console.log(gt.getLocaleName()); // "French (France)"

// Get the names for other locales
console.log(gt.getLocaleName('es')); // "Spanish (Spain)"
console.log(gt.getLocaleName('de')); // "German (Germany)"
console.log(gt.getLocaleName('ja')); // "Japanese (Japan)"

Notes

  • The method uses the instance’s sourceLocale to determine the display language
  • Custom mapping names take precedence over standard Intl.DisplayNames

Next steps

  • Get the locale emoji with getLocaleEmoji
  • Get comprehensive locale info with getLocaleProperties
  • Learn about the CustomMapping type](/docs/core/types/custom-mapping)

How is this guide?

getLocaleName