forked from YunoHost/apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseparate_locales_between_lists.py
40 lines (29 loc) · 1.29 KB
/
separate_locales_between_lists.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
import os
import sys
import json
# TODO
# when an app is moved from one list to another find a way to migrate string?
if __name__ == '__main__':
# en = json.load(open("locales/en.json", "r"))
for apps_list in sys.argv[1:]:
if not os.path.exists(apps_list):
print "Error: file %s doesn't exists" % apps_list
sys.exit(1)
folder = "locales-%s" % (apps_list.split(".")[0])
apps_list = json.load(open(apps_list, "r"))
apps = tuple(apps_list.keys())
if not os.path.exists(folder):
os.mkdir(folder)
for existing_translations in os.listdir("locales"):
if not existing_translations.endswith(".json"):
print "skip non json file %s", existing_translations
continue
language = existing_translations[:-len(".json")]
existing_translations = json.load(open("locales/" + existing_translations, "r"))
new_content = {}
for key, value in existing_translations.items():
if key.startswith(apps):
new_content[key] = value
file_name = folder + "/" + language + ".json"
print "writting %s..." % file_name
open(file_name, "w").write(json.dumps(new_content, sort_keys=True, indent=4))