forked from YunoHost/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_translation_file.py
57 lines (40 loc) · 1.94 KB
/
generate_translation_file.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
import os
import sys
import json
if __name__ == '__main__':
if os.path.exists("locales/en.json"):
print "This script should be run only once, the first time to generate locales/, after that you should use update_translations.py"
print "Abort"
sys.exit(1)
other_langs = {}
keys = []
en = {}
for builded_file in sys.argv[1:]:
builded_file = json.load(open(builded_file, "r"))
for app, data in builded_file.items():
if "en" in data["manifest"]["description"]:
key = "%s_manifest_description" % app
en[key] = data["manifest"]["description"]["en"]
keys.append(key)
for i in data["manifest"]["description"]:
if i not in other_langs:
other_langs[i] = {x: "" for x in keys}
for i, translations in other_langs.items():
translations[key] = data["manifest"]["description"].get(i, "")
for category, questions in data["manifest"]["arguments"].items():
for question in questions:
if "en" not in question["ask"]:
continue
key = "%s_manifest_arguments_%s_%s" % (app, category, question["name"])
en[key] = question["ask"]["en"]
keys.append(key)
for i in question["ask"]:
if i not in other_langs:
other_langs[i] = {x: "" for x in keys}
for i, translations in other_langs.items():
translations[key] = question["ask"].get(i, "")
if not os.path.exists("locales"):
os.makedirs("locales")
open("locales/en.json", "w").write(json.dumps(en, sort_keys=True, indent=4))
for i, translations in other_langs.items():
open("locales/%s.json" % i, "w").write(json.dumps(translations, sort_keys=True, indent=4))