getLocaleEmoji
API reference for the standalone getLocaleEmoji function
Overview
The standalone getLocaleEmoji function retrieves an emoji flag or symbol for a locale code without requiring a GT class instance.
It returns the appropriate flag emojis for countries and territories based on the localeβs region, with support for custom emoji mappings.
import { getLocaleEmoji } from 'generaltranslation';
const emoji = getLocaleEmoji('fr-CA');
console.log(emoji); // "π¨π¦" (Canada flag)
const usEmoji = getLocaleEmoji('en-US');
console.log(usEmoji); // "πΊπΈ" (US flag)Reference
Parameters
Prop
Type
Parameter descriptions
| Parameter | Description |
|---|---|
locale | BCPβ47 locale code to retrieve the emoji for |
customMapping | Optional custom mapping for locale codes and emoji overrides |
Returns
string - Emoji flag or symbol representing the locale:
- Country/territory flag emoji for locales with regions (e.g.,
πΊπΈ,π«π·,π―π΅) - Custom emoji if defined in mapping
- Default flag emoji (
π³οΈ) for unrecognised locales
Examples
Basic emoji retrieval
import { getLocaleEmoji } from 'generaltranslation';
// Common country flags
console.log(getLocaleEmoji('en-US')); // "πΊπΈ"
console.log(getLocaleEmoji('fr-FR')); // "π«π·"
console.log(getLocaleEmoji('de-DE')); // "π©πͺ"
console.log(getLocaleEmoji('ja-JP')); // "π―π΅"
console.log(getLocaleEmoji('zh-CN')); // "π¨π³"
// Regions with multiple languages
console.log(getLocaleEmoji('en-CA')); // "π¨π¦"
console.log(getLocaleEmoji('fr-CA')); // "π¨π¦"
console.log(getLocaleEmoji('de-CH')); // "π¨π"
console.log(getLocaleEmoji('fr-CH')); // "π¨π"Notes
- Returns flag emojis using Unicode Regional Indicator Symbols
- Custom-mapped emojis take precedence over region-based selection
- Supports all ISO 3166-1 alpha-2 region codes for comprehensive coverage
Next steps
- Use the GT class method
getLocaleEmoji - Retrieve locale properties with
getLocaleProperties - Retrieve locale names with
getLocaleName - Validate locales with
isValidLocale
How is this guide?