getLocaleProperties
API Reference for the standalone getLocaleProperties function
Overview
The standalone getLocaleProperties function retrieves properties for a locale code without requiring a GT class instance.
It provides detailed information including display names, region codes, script information, and emoji flags in a complete LocaleProperties object.
import { getLocaleProperties } from 'generaltranslation';
const props = getLocaleProperties('fr-CA', 'en');
console.log(props.name); // "French (Canada)"
console.log(props.nativeName); // "français (Canada)"
console.log(props.emoji); // "🇨🇦"
console.log(props.regionCode); // "CA"Reference
Parameters
Prop
Type
Parameters Description
| Parameter | Description |
|---|---|
locale | BCP-47 locale code to get properties for |
defaultLocale | Locale to use for localizing display names (defaults to 'en') |
customMapping | Optional custom mapping for locale codes and properties |
Returns
LocaleProperties - A comprehensive object containing all locale information:
code: Standardized locale codename: Display name in default 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
Behavior
Custom Mapping Integration
- Custom mappings are checked first for all properties
- Supports alias resolution and property overrides
- Falls back to standard Intl APIs for unmapped codes
- Canonical locale resolution for aliased locales
Examples
import { getLocaleProperties } from 'generaltranslation';
// English display names
const enProps = getLocaleProperties('es-MX', 'en');
console.log(enProps.name); // "Spanish (Mexico)"
console.log(enProps.languageName); // "Spanish"
console.log(enProps.regionName); // "Mexico"
console.log(enProps.emoji); // "🇲🇽"
// French display names
const frProps = getLocaleProperties('es-MX', 'fr');
console.log(frProps.name); // "espagnol (Mexique)"
console.log(frProps.languageName); // "espagnol"
console.log(frProps.regionName); // "Mexique"
// Native names are always in the target locale
console.log(enProps.nativeName); // "español (México)"
console.log(frProps.nativeName); // "español (México)"Notes
- Function provides locale data without GT class instantiation
- Custom mapping properties take precedence over standard Intl APIs
- The complete
LocalePropertiesinterface is always returned - Native names are always computed in the target locale itself
Next Steps
- Explore
LocalePropertiesinterface - Complete interface documentation - Use GT class method
getLocaleProperties - Get simple locale names with
getLocaleName - Get locale emoji with
getLocaleEmoji
How is this guide?