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 information, and emoji flags.
It returns a complete LocaleProperties object with all necessary data for building rich internationalized 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
Parameters Description
| Parameter | Description |
|---|---|
locale | BCP-47 locale code to get properties for. If not provided, uses the instance's targetLocale |
Returns
LocaleProperties - A comprehensive object containing all locale information:
code: Standardized locale codename: Display name in 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 respect the instance's
sourceLocalesetting - Custom mapping properties take precedence over standard Intl APIs
Next Steps
- Explore
LocalePropertiesinterface - Get simple locale names with
getLocaleName - Get locale emoji with
getLocaleEmoji - Learn about
CustomMappingtype
How is this guide?