-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndexTranslations.py
41 lines (30 loc) · 1.04 KB
/
IndexTranslations.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
def find_translation_files(base_path):
files = {}
pathes = [path for path in os.listdir(base_path)]
full_pathes = [os.path.join(base_path, path) for path in pathes]
directories = filter(lambda p: os.path.isdir(p), full_pathes)
for path in pathes:
full_path = os.path.join(base_path, path)
if os.path.isfile(full_path) and path.endswith(".yml"):
add_array(files, base_path, {
"lang": path.replace(".yml", ""),
"path": full_path
})
for directory in directories:
files = merge_dicts(files, find_translation_files(directory))
return files
def add_array(dictionary, key, item):
if key in dictionary:
dictionary[key].append(item)
else:
dictionary[key] = [item]
def merge_dicts(*dicts):
output = {}
for d in dicts:
for _, (key, array) in enumerate(d.items()):
if key in output:
output[key] += array
else:
output[key] = array
return output