-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_translations.py
More file actions
83 lines (70 loc) · 2.52 KB
/
check_translations.py
File metadata and controls
83 lines (70 loc) · 2.52 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json
import os
files = [
'articles.json',
'blog.json',
'common.json',
'government.json',
'home.json',
'pages.json',
'platform.json',
'solutions.json',
'wallet.json'
]
base_en = '/Users/sergey/github/folio/src/locales/en'
base_es = '/Users/sergey/github/folio/src/locales/es'
def get_keys_recursive(data, parent_key=''):
keys = set()
for k, v in data.items():
curr_key = f"{parent_key}.{k}" if parent_key else k
if isinstance(v, dict):
keys.update(get_keys_recursive(v, curr_key))
else:
keys.add(curr_key)
return keys
print("Missing translations check:")
for filename in files:
en_path = os.path.join(base_en, filename)
es_path = os.path.join(base_es, filename)
if not os.path.exists(en_path):
print(f"Skipping {filename} (EN invalid)")
continue
if not os.path.exists(es_path):
print(f"Skipping {filename} (ES invalid)")
continue
try:
with open(en_path, 'r') as f:
en_data = json.load(f)
with open(es_path, 'r') as f:
es_data = json.load(f)
en_keys = get_keys_recursive(en_data)
es_keys = get_keys_recursive(es_data)
missing = en_keys - es_keys
if missing:
print(f"\n[{filename}] Missing {len(missing)} keys:")
for k in sorted(list(missing))[:10]:
print(f" - {k}")
if len(missing) > 10:
print(f" ... and {len(missing) - 10} more")
else:
print(f"\n[{filename}] OK")
# Check for values that might be identical (potential untranslated copies)
# This is a heuristic
untranslated_count = 0
for k in en_keys.intersection(es_keys):
# Navigate to value
keys = k.split('.')
en_val = en_data
es_val = es_data
for key in keys:
en_val = en_val[key]
es_val = es_val[key]
if isinstance(en_val, str) and en_val == es_val and len(en_val) > 3:
# Ignore short strings or common words typically same
# But list them if they look like sentences
if ' ' in en_val:
untranslated_count += 1
if untranslated_count > 0:
print(f"[{filename}] Warning: {untranslated_count} identical values (potentially untranslated)")
except Exception as e:
print(f"Error processing {filename}: {e}")