-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
create_translation_info.py
34 lines (26 loc) · 1.08 KB
/
create_translation_info.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
#!/usr/bin/env python3
import json
import glob
from contextlib import suppress
from operator import itemgetter
from babel import Locale
complete = []
incomplete = []
for fn in glob.glob("orisa/locale/stats/*_stats.json"):
with open(fn) as f:
data = json.load(f)
loc = data["code"]
data["native_name"] = Locale.parse(loc).get_display_name(loc).title()
with suppress(IOError):
with open(f"orisa-web/src/locale/info/{loc}_info.json") as f:
data["web_percent_translated"] = json.load(f)["percent_translated"]
if data["percent_translated"] >= 95:
complete.append(data)
else:
incomplete.append(data)
complete.append({"code": "en", "name": "English", "native_name": "English", "percent_translated": 100, "web_percent_translated": 100})
complete.sort(key=itemgetter("native_name"))
incomplete.sort(key=itemgetter("native_name"))
info = {"complete": complete, "incomplete": incomplete}
with open("orisa-web/src/generated/translation_info.json", "w", encoding="utf-8") as f:
json.dump(info, f, ensure_ascii=False, separators=",:")