From 63076758a3830631f40914c685efd003a22b69fa Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Thu, 24 Sep 2020 14:05:47 +0200 Subject: [PATCH] [i18n] Check for redundancy in localized messages After parsing the .i18n files, compare the messages and raise an error if some of them could be factored into a universal file. Change-Id: I0dcfe309dc4c310555a0ea16b6d1680e51a8e87d --- apps/i18n.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/i18n.py b/apps/i18n.py index 3c688d64e..d03ec1ede 100644 --- a/apps/i18n.py +++ b/apps/i18n.py @@ -71,6 +71,18 @@ def split_line(line): def locale_from_filename(filename): return re.match(r".*\.([a-z]+)\.i18n", filename).group(1) +def check_redundancy(messages, data, locales): + redundant_names = set() + for name in messages: + redundancy = True + for i in range(1, len(locales)): + redundancy = redundancy and data[locales[i]][name] == data[locales[i-1]][name] + if redundancy: + redundant_names.add(name) + if (len(redundant_names) > 0): + sys.stderr.write("Some localized messages are redundant and can be made universal :\n\t" + "\n\t".join(sorted(redundant_names)) + "\n") + sys.exit(-1) + def parse_files(files): data = {} messages = set() @@ -95,6 +107,7 @@ def parse_files(files): else: messages.add(name) data[locale][name] = definition + check_redundancy(messages, data, args.locales) return {"messages": sorted(messages), "universal_messages": sorted(universal_messages), "data": data} def parse_codepoints(file):