GT ClassMethodsLocales

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

ParameterDescription
localeBCP-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 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 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

How is this guide?

getLocaleEmoji