forked from harmonoid/localizations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci.py
41 lines (40 loc) · 1.83 KB
/
ci.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
import os
import sys
import json
from typing import List, Dict
if __name__ == "__main__":
success: bool = True
current_dir: str = os.getcwd()
translations_dir = os.path.join(current_dir, "translations")
# Check whether all languages contain en-US equivalent key/value entries.
# Get available keys in en-US.
keys: List[str] = []
with open(os.path.join(translations_dir, "en_US.json"), "r", encoding="utf_8") as file:
keys.extend(json.loads(file.read()).keys())
# Check if any language has some key missing.
for file in os.listdir(translations_dir):
if file.endswith(".json"):
with open(os.path.join(translations_dir, file), "r", encoding="utf_8") as file:
contents: Dict[str, str] = json.loads(file.read())
for key in keys:
if key not in contents:
print(f"{file.name}: {key} not found.")
success = False
languages: List[Dict[str, str]] = []
# Check whether all entries in index.json are valid i.e. equivalent translation file exists.
with open(os.path.join(current_dir, "index.json"), "r", encoding="utf_8") as file:
languages = json.loads(file.read())
for l in languages:
if not os.path.isfile(os.path.join(translations_dir, f"{l['code']}.json")):
print(f"{l['code']}.json not found.")
success = False
language_codes = list(map(lambda l: l["code"], languages))
# Check whether all translation files i.e. ll-RR.json have an entry in index.json.
for file in os.listdir(translations_dir):
if file.endswith(".json"):
if file.split(".")[0] not in language_codes:
print(f"{file} not found in index.json.")
success = False
# Exit code.
if not success:
sys.exit(1)