getLocaleEmoji
API Reference for the GT getLocaleEmoji method
Overview
The getLocaleEmoji method retrieves an emoji flag or symbol for a locale code based on its region.
It returns appropriate flag emojis for countries and territories, with fallbacks for languages without specific regions and custom emoji support through mappings.
const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'fr-CA'
});
const emoji = gt.getLocaleEmoji('fr-CA');
console.log(emoji); // "π¨π¦" (Canadian flag)
const usEmoji = gt.getLocaleEmoji('en-US');
console.log(usEmoji); // "πΊπΈ" (US flag)
const enEmoji = gt.getLocaleEmoji('en');
console.log(enEmoji); // "πΊπΈ" (US flag)Reference
Parameters
Prop
Type
Parameters Description
| Parameter | Description | 
|---|---|
| locale | BCP-47 locale code to get emoji for. If not provided, uses the instance's targetLocale | 
Returns
string - Emoji flag or symbol representing the locale:
- Country/territory flag emoji for locales with regions (e.g., πΊπΈ,π«π·,π―π΅)
- Language-specific emoji for some languages without regions
- Default flag emoji (π³οΈ) for unrecognized locales
Throws
- Error- If no locale is provided and the instance has no- targetLocaleconfigured
Examples
const gt = new GT({
  sourceLocale: 'en',
  targetLocale: 'es'
});
// Get emoji for target locale
console.log(gt.getLocaleEmoji()); // "πͺπΈ" (uses targetLocale 'es')
// Get emojis for different locales
console.log(gt.getLocaleEmoji('en-US')); // "πΊπΈ"
console.log(gt.getLocaleEmoji('fr-FR')); // "π«π·"
console.log(gt.getLocaleEmoji('de-DE')); // "π©πͺ"
console.log(gt.getLocaleEmoji('ja-JP')); // "π―π΅"
console.log(gt.getLocaleEmoji('zh-CN')); // "π¨π³"Notes
- Returns flag emojis based on the locale's region code when available
- Custom mapping emojis take priority over region-based selection
- Uses Unicode regional indicator symbols for flag generation
- Defaults to π³οΈ(white flag) for unrecognized or invalid locales
- Compatible with all modern browsers and operating systems that support Unicode emojis
Next Steps
- Get locale properties with getLocaleProperties
- Get locale names with getLocaleName
- Validate locales with isValidLocale
- Learn about CustomMapping type](/docs/core/types/custom-mapping)
How is this guide?

