Fix twlang decode to handle context lines properly

Context line is always one line above. If we don't do this we end up
with empty [Graphics] context lines in the translation files.
This commit is contained in:
Dennis Felsing 2023-02-25 10:35:29 +01:00
parent c3a0a5e700
commit 5ee7ffa33f

View file

@ -59,12 +59,16 @@ def decode(fileobj, elements_per_key):
data[current_key].append(index)
if line in data:
raise LanguageDecodeError("Key defined multiple times: " + line, fileobj.name, index)
data[(line, current_context)] = [index]
data[(line, current_context)] = [index - 1 if current_context else index]
current_key = (line, current_context)
if len(data[current_key]) != 1+elements_per_key:
raise LanguageDecodeError("Wrong number of elements per key", fileobj.name, index)
data[current_key].append(index+1)
return data
new_data = {}
for key, value in data.items():
if key[0]:
new_data[key] = value
return new_data
def check_file(path):
@ -78,7 +82,7 @@ def check_folder(path):
for path2, dirs, files in os.walk(path):
dirs.sort()
for f in sorted(files):
if not any(f.endswith(x) for x in ".cpp .c .h".split()):
if not any(f.endswith(x) for x in [".cpp", ".c", ".h"]):
continue
for sentence in check_file(os.path.join(path2, f)):
englishlist[sentence[1:]] = None