PICARD-1929: Use English as default for empty NSIS translations

NSIS will by itself not allow empty translatons, hence make sure to handle empty strings on tranlation import.
This commit is contained in:
Philipp Wolfer
2020-08-28 09:28:58 +02:00
parent 01f13ad02f
commit 0e346f5307

View File

@@ -36,10 +36,23 @@ def write_langstring(f, language, identifier, text):
f.write(langstring)
def merge_translations(*translations):
merged = {}
for trans in translations:
for k, v in trans.items():
if v:
merged[k] = v
return merged
def main():
scriptdir = os.path.dirname(os.path.abspath(__file__))
sourcesdir = os.path.join(scriptdir, 'sources')
# Read the english sources for defaults
with open(os.path.join(sourcesdir, 'en.json'), 'r', encoding='utf-8') as infile:
data_en = json.loads(infile.read())
for path in glob.glob(os.path.join(sourcesdir, '*.json')):
language, language_code = language_from_filename(path)
if not language:
@@ -48,6 +61,7 @@ def main():
target_file = os.path.join(scriptdir, f'{language}.nsh')
with open(path, 'r', encoding='utf-8') as infile:
data = json.loads(infile.read())
data = merge_translations(data_en, data)
with open(target_file, 'w+', encoding='utf-8') as outfile:
for identifier, text in data.items():
write_langstring(outfile, language, identifier, text)