getLocaleProperties
API reference for the GT getLocaleProperties method
Overview
The getLocaleProperties method retrieves comprehensive properties for a locale code, providing
detailed information including display names, region codes, script details, and emoji flags.
It returns a complete LocaleProperties object with all the data needed to build rich, internationalised user interfaces.
const gt = new GT({
sourceLocale: 'en',
targetLocale: 'es'
});
const props = gt.getLocaleProperties('fr-CA');
console.log(props.name); // "French (Canada)"
console.log(props.nativeName); // "français (Canada)"
console.log(props.emoji); // "🇨🇦"Reference
Parameters
Prop
Type
Parameter Description
| Parameter | Description |
|---|---|
locale | BCP 47 locale code to retrieve properties for. If not provided, uses the instance’s targetLocale. |
Returns
LocaleProperties - A comprehensive object containing all locale information:
code: Standardised locale codename: Display name in the source localenativeName: Display name in the locale itselflanguageCode,languageName,nativeLanguageName: Language informationregionCode,regionName,nativeRegionName: Region informationscriptCode,scriptName,nativeScriptName: Script informationmaximizedCode,minimizedCode: Canonical formsnameWithRegionCode,nativeNameWithRegionCode: Combined display formatsemoji: Flag or representative emoji
Throws
Error– if no locale is provided and the instance has notargetLocaleconfigured
Examples
Basic usage
const gt = new GT({
sourceLocale: 'en',
targetLocale: 'fr'
});
// Get properties for target locale
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); // "🇫🇷"
// Get properties for other locales
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"Notes
- All display names follow the instance’s
sourceLocalesetting - Custom mapping properties take precedence over standard Intl APIs
Next steps
- Explore the
LocalePropertiesinterface - Get simple locale names with
getLocaleName - Get locale emoji with
getLocaleEmoji - Learn about the
CustomMappingtype
How is this guide?