From 5ee7ffa33fface0acd6a3676b8d041cc1aa5195d Mon Sep 17 00:00:00 2001 From: Dennis Felsing Date: Sat, 25 Feb 2023 10:35:29 +0100 Subject: [PATCH] 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. --- scripts/languages/twlang.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/scripts/languages/twlang.py b/scripts/languages/twlang.py index c682cd282..6508a79c1 100644 --- a/scripts/languages/twlang.py +++ b/scripts/languages/twlang.py @@ -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