Fix Greek translation and check for similar issues in the future

This commit is contained in:
Anders Jenbo
2026-08-02 14:25:55 +02:00
parent febf576b3c
commit 5244ceb591
2 changed files with 40 additions and 5 deletions
+2 -2
View File
@@ -7313,8 +7313,8 @@ msgstr "Δεξιότητα"
#: Source/panels/spell_book.cpp:162
msgid "Staff ({:d} charge)"
msgid_plural "Staff ({:d} charges)"
msgstr[0] "Ράβδος ({:d} φορτίο}"
msgstr[1] "Ράβδος ({:d} φορτία}"
msgstr[0] "Ράβδος ({:d} φορτίο)"
msgstr[1] "Ράβδος ({:d} φορτία)"
#. TRANSLATORS: UI constraints, keep short please.
#: Source/panels/spell_book.cpp:167
+38 -3
View File
@@ -4,24 +4,59 @@ from glob import glob
import polib
import re
def extractFmtFields(text):
"""Parse fmt-style replacement fields, mirroring fmt's own escaping rules
("{{" and "}}" are literal braces). Returns None if a brace is unmatched
or unescaped, which fmt::format would reject at runtime with a
format_error (crash)."""
fields = []
i = 0
n = len(text)
while i < n:
c = text[i]
if c == '{':
if i + 1 < n and text[i + 1] == '{':
i += 2
continue
end = text.find('}', i)
if end == -1:
return None
fields.append(text[i:end + 1])
i = end + 1
elif c == '}':
if i + 1 < n and text[i + 1] == '}':
i += 2
continue
return None
else:
i += 1
return fields
def validateEntry(original, translation):
if translation == '':
return True
# Find fmt arguments in source message
src_arguments = re.findall("{.*?}", original)
src_arguments = extractFmtFields(original)
if src_arguments is None:
print ("\033[31mMalformed format string in source message: " + original + "\033[0m")
return False
if len(src_arguments) == 0:
return True
# Find fmt arguments in translation
translated_arguments = re.findall("{.*?}", translation)
translated_arguments = extractFmtFields(translation)
if translated_arguments is None:
print ("\033[36m" + original + "\033[0m has an unmatched/unescaped brace in \033[31m" + translation + "\033[0m")
return False
# If paramteres are untyped with order, sort so that they still appear equal if reordered
# Note: This does no hadle cases where the translator reordered arguments where not expected
# by the source. Or other advanced but valid usages of the fmt syntax
isOrdered = True
for argument in src_arguments:
if re.search("^{\d+}$", argument) == None:
if re.search(r"^{\d+}$", argument) == None:
isOrdered = False
break