Utility FunctionsLocales

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 details, and emoji flags, in a complete LocaleProperties object.

import { getLocaleProperties } from 'generaltranslation';

const props = getLocaleProperties('fr-CA', 'en-GB');
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

ParameterDescription
localeBCP‑47 locale code to retrieve properties for
defaultLocaleLocale used to localise display names (defaults to 'en')
customMappingOptional custom mapping for locale codes and properties

Returns

LocaleProperties - A comprehensive object containing all locale information:

  • code: Standardised locale code
  • name: Display name in the default locale
  • nativeName: Display name in the locale itself
  • languageCode, languageName, nativeLanguageName: Language information
  • regionCode, regionName, nativeRegionName: Region information
  • scriptCode, scriptName, nativeScriptName: Script information
  • maximizedCode, minimizedCode: Canonical forms
  • nameWithRegionCode, nativeNameWithRegionCode: Combined display formats
  • emoji: Flag or representative emoji

Behaviour

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

  • Provides locale data without instantiating the GT class
  • Custom mapping properties take precedence over standard Intl APIs
  • The full LocaleProperties interface is always returned
  • Native names are always computed in the target locale itself

Next steps

How is this guide?

getLocaleProperties