Skip to content

Commit

Permalink
Add support for multiple languages
Browse files Browse the repository at this point in the history
  • Loading branch information
fedecalendino committed Dec 15, 2022
1 parent f93eab0 commit 3d9ed30
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 12 deletions.
Binary file modified img/screenshots/config.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/screenshots/usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,49 @@
<key>variable</key>
<string>keyword</string>
</dict>
<dict>
<key>config</key>
<dict>
<key>default</key>
<string>en</string>
<key>pairs</key>
<array>
<array>
<string>🇬🇧 English</string>
<string>en</string>
</array>
<array>
<string>🇩🇪 Deutsche</string>
<string>de</string>
</array>
<array>
<string>🇪🇸 Español</string>
<string>es</string>
</array>
<array>
<string>🇫🇷 Français</string>
<string>fr</string>
</array>
<array>
<string>🇮🇹 Italiano</string>
<string>it</string>
</array>
<array>
<string>🇵🇹 Português</string>
<string>pt</string>
</array>
</array>
</dict>
<key>description</key>
<string>Select the language you prefer.
note: not all emojis are available in all languages.</string>
<key>label</key>
<string>Language</string>
<key>type</key>
<string>popupbutton</string>
<key>variable</key>
<string>LANG</string>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down
38 changes: 26 additions & 12 deletions src/emojis.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ def clean(name: str) -> str:


def build():
names = defaultdict()
normal_emojis = defaultdict(list)
skin_toned_emojis = defaultdict(list)
aliased_emojis = defaultdict(list)

lang = os.getenv("LANG", "en").lower()

skin_tone = os.getenv("SKIN_TONE", "light").lower()
skin_tone = VALID_SKIN_TONES.get(skin_tone)

Expand All @@ -31,49 +34,60 @@ def build():
if data["status"] != 2: # fully_qualified
continue

name = data["en"]
if not data.get(lang):
continue

key = data["en"]

if "flag_for" in name:
if "flag_for" in key:
continue

prioritize_skin_tone = False

# change or skip unwanted skin tones
if "skin_tone" in name:
if skin_tone not in name:
if "skin_tone" in key:
if skin_tone not in key:
continue

name = name.replace(skin_tone, "", 1)
key = key.replace(skin_tone, "", 1)
prioritize_skin_tone = True

name = clean(name)
key = clean(key)
code = f"{emoji}\U0000FE0F"
uuid = uuid4()

if prioritize_skin_tone:
# reuse the same uuid as the non skin toned version
normal = normal_emojis.get(name)
normal = normal_emojis.get(key)

if normal:
uuid = normal[0][0]

skin_toned_emojis[name].append((uuid, code))
skin_toned_emojis[key].append((uuid, code))
else:
normal_emojis[name].append((uuid, code))
normal_emojis[key].append((uuid, code))

names[uuid] = clean(data[lang])

# add all aliases for that specific emoji
for alias in data.get("alias", []):
if "flag_for" in alias:
continue

aliased_emojis[uuid].append(clean(alias))
alias = clean(alias)

if key != alias:
aliased_emojis[uuid].append(alias)

# replace the selected skin toned emojis over the non skin toned
normal_emojis.update(skin_toned_emojis)

for name, codes in normal_emojis.items():
for key, codes in normal_emojis.items():
for uuid, code in codes:
yield name, code
yield names[uuid], code

if lang != "en":
continue

for alias in aliased_emojis.get(uuid, []):
yield alias, code
Expand Down

0 comments on commit 3d9ed30

Please sign in to comment.