forked from fsfe/reuse-website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_translations.py
56 lines (43 loc) · 1.47 KB
/
check_translations.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
"""Check which i18n translation files contain all index_ strings from EN"""
# SPDX-FileCopyrightText: Free Software Foundation Europe e.V.
#
# SPDX-License-Identifier: GPL-3.0-or-later
import json
import glob
import sys
import os
basedir = os.path.realpath(sys.argv[1])
# Load English strings in a dict
with open(f"{basedir}/en.json", encoding="UTF-8") as jsonfile:
en = json.load(jsonfile)
# Clear status file
with open(f"{basedir}/.status", 'w'): pass
# load all index strings
indexes = []
for k,v in en.items():
if k.startswith("index_"):
indexes.append(k)
# get all i18n string files
i18nfiles = glob.glob(f"{basedir}/*.json")
# Interate through translation files and check their completeness
for trans in i18nfiles:
lang = os.path.splitext(os.path.basename(trans))[0]
# skip English
if lang == "en":
continue
else:
# initialise key counter
transstrings = 0
# Load JSON file
with open(trans, encoding="UTF-8") as jsonfile:
trans = json.load(jsonfile)
# Check for all important strings whether they exist in translation
for key in indexes:
if key in trans:
transstrings += 1
# Check if same amount of strings available
if transstrings == len(indexes):
with open(f"{basedir}/.status", "a") as statusfile:
statusfile.write(f"{lang}\n")
else:
print(f"[WARN] Important keys for \"{lang}\" not complete!")