GT ClassMethodsLocales

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

ParameterDescription
localeBCPโ€‘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 no targetLocale configured

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

How is this guide?

getLocaleEmoji