Search code examples
swiftemojiswift-string

How could I get Apple emoji name instead of Unicode name?


I see that the Unicode name of an emoji and its Apple name as displayed in Character Viewer are different. How could I get an emoji's Apple name using Swift?

Example:

Emoji: 😄

Unicode Name (got via .applyingTransform(.toUnicodeName, reverse: false)):

smiling face with open mouth and smiling eyes

Apple Name (got from macOS Character Viewer):

grinning face with squinting eyes


Solution

  • The first one is the Unicode name, though the correct name is:

    SMILING FACE WITH OPEN MOUTH AND SMILING EYES
    

    The fact that it's uppercase matters. It's a Unicode identifier. It's permanent and it's unique. (It's really permanent, even if they misspell a word like "BRAKCET" in "PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET", that name is forever).

    The second name is the "Apple Name." These are localized names. On Mac, the English version is stored in:

    /System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/AppleName.strings
    

    You can dump this file with plutil, or read it using PropertyListDecoder.

    $ plutil -p AppleName.strings
    {
      "〰" => "wavy dash"
      "‼️" => "red double exclamation mark"
      "⁉️" => "red exclamation mark and question mark"
      "*️⃣" => "keycap asterisk"
      "#️⃣" => "number sign"
      "〽️" => "part alternation mark"
      "©" => "copyright sign"
      ...
    

    That said, unless you absolutely need to match Apple, I'd recommend the CLDR (Common Locale Data Repository) annotation short name. That's the Unicode source for localized names. They're not promised to be unique, though. Their biggest purpose is for supporting text-to-speech.

    For the current list in XML, it's most convenient on GitHub. Or you can browse the v37 table or download the raw data.