-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.py
59 lines (41 loc) · 1.47 KB
/
translate.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
import os
import requests
EMOJIBASE_VERSION = "15.3.0"
def load_emojibase(locale):
print(f"Loading {locale}...")
url = f"https://cdn.jsdelivr.net/npm/emojibase-data@{EMOJIBASE_VERSION}/{locale}/data.json"
return requests.get(url).json()
def load_emojimart():
print("Loading emojimart...")
url = "https://cdn.jsdelivr.net/npm/@emoji-mart/data"
return requests.get(url).json()
emojimart = load_emojimart()
def translate(locale):
emojibase = load_emojibase(locale)
emojis = {}
translated = 0
for k, v in emojimart["emojis"].items():
emoji = emojimart["emojis"][k]
skin = emoji["skins"][0]
hexcode = skin["unified"].upper()
hexcode2 = hexcode.split("-")[0]
if skin:
base = [x for x in emojibase if x["hexcode"] == hexcode]
if not base:
base = [x for x in emojibase if x["hexcode"] == hexcode2]
if base:
base = base[0]
emoji["keywords"] = base.get("tags") or emoji["keywords"]
emoji["name"] = base["label"].capitalize()
translated += 1
emojis[k] = emoji
emojimart["emojis"] = emojis
if not os.path.exists(f"./data/{locale}"):
os.makedirs(f"./data/{locale}")
print(f"Translated {translated} emojis")
open(f"./locales/{locale}/data.json", "w").write(
json.dumps(emojimart, ensure_ascii=False)
)
locale = input("Enter locale: ")
translate(locale)