createLocalizedStringFromEmojiCodes static method

String createLocalizedStringFromEmojiCodes(
  1. BuildContext context,
  2. String text
)

Convert emoji codes in text to localized names e.g., "abcTUIEmoji_Smiledef" -> "abc微笑def" (Chinese) or "abcSmiledef" (English)

Implementation

static String createLocalizedStringFromEmojiCodes(BuildContext context, String text) {
  if (text.isEmpty) {
    return text;
  }

  final emojiMap = getEmojiMap(context);
  String result = text;

  // Sort by key length descending to handle longer keys first
  final sortedKeys = emojiMap.keys.toList()..sort((a, b) => b.length.compareTo(a.length));

  for (final key in sortedKeys) {
    if (result.contains(key)) {
      result = result.replaceAll(key, emojiMap[key]!);
    }
  }

  return result;
}