getLocaleEmoji
API reference for the GT getLocaleEmoji method
Overview
The getLocaleEmoji method returns an emoji flag or symbol for a locale code based on its region.
It provides appropriate flag emojis for countries and territories, with fallbacks for languages without specific regions, and supports custom emojis via 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 retrieve the emoji for. If not provided, it 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 unrecognised locales
Throws
Errorโ if no locale is provided and the instance has notargetLocaleconfigured
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 to generate flags
- Defaults to
๐ณ๏ธ(white flag) for unrecognised 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 the
CustomMappingtype](/docs/core/types/custom-mapping)
How is this guide?