[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
This commit is contained in:
Gabriel Ozouf
2020-09-24 14:05:47 +02:00
committed by Émilie Feral
parent 3019609946
commit 63076758a3

View File

@@ -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):