mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[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:
committed by
Émilie Feral
parent
3019609946
commit
63076758a3
13
apps/i18n.py
13
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):
|
||||
|
||||
Reference in New Issue
Block a user