-
Notifications
You must be signed in to change notification settings - Fork 2
/
move_translations_to_proj.py
48 lines (39 loc) · 1.58 KB
/
move_translations_to_proj.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
'''
Moves translated values to the project
'''
import os
import json
from shared import app_root, locales
from shared import save, read_obj, get_translations
dirs_to_walk = ['scenes', 'components', 'services']
def walk():
translations = get_translations(locales)
try:
for dir in dirs_to_walk:
for root, dirs, files in os.walk(os.path.join(app_root, dir)):
for file in files:
file_name = file.split('.')[0]
if file_name in locales and file_name in translations:
path = os.path.join(root, file)
en_path = os.path.join(root, file.replace(file_name + ".json", "en.json"))
#obj = read_obj(path)
en_obj = read_obj(en_path)
for key in translations[file_name]:
if key in en_obj:
en_obj[key] = translations[file_name][key]
save(en_obj, path)
except Exception as e:
print(str(e) + " " + path)
def copy():
for dir in dirs_to_walk:
for root, dirs, files in os.walk(os.path.join(app_root, dir)):
for file in files:
file_name = file.split('.')[0]
if file_name == 'en':
path = os.path.join(root, file)
data = read_obj(path)
for locale in locales:
if locale != 'en':
save(data, os.path.join(root, locale + '.json'))
if __name__ == '__main__':
walk()