Column checker: Also understand `: ::`.

This commit is contained in:
Julien Palard 2023-04-08 16:39:05 +02:00
parent 347cad0b60
commit d16166d2df
Signed by: mdk
GPG Key ID: 0EFC1AC1006886F8
1 changed files with 25 additions and 13 deletions

View File

@ -5,25 +5,37 @@ from itertools import chain
import polib
def colon_is_visible(msg):
if msg.endswith(": ::"):
return True
if msg.endswith(" ::"):
return False
if msg.endswith("::"):
return True
raise ValueError("Don't know if msg ends with a visible or an invisible colon.")
def check(file):
check = '--check' in sys.argv
pofile = polib.pofile(file)
has_errors = False
for entry in pofile:
if not entry.msgstr:
continue
if entry.msgid.endswith(" ::"):
fixed = entry.msgstr.rstrip(": \u202f\u00A0") + " ::"
if check and entry.msgstr != fixed:
print(f"{file}:{entry.linenum}: Expected translation to end with: ' ::'")
has_errors = True
entry.msgstr = fixed
elif entry.msgid.endswith("::"):
fixed = entry.msgstr.rstrip(": ,. \u202f\u00A0") + "\u00A0::"
if check and entry.msgstr != fixed:
print(rf"{file}:{entry.linenum}: Expected translation to end with: '\u00A0::'")
has_errors = True
entry.msgstr = fixed
continue # No need to check untranslated entries.
if not entry.msgid.endswith("::"):
continue # No need to work on entries not ending with a colon.
fixed = entry.msgstr.rstrip(": \u202f\u00A0")
if colon_is_visible(entry.msgid):
fixed += "\u00A0::"
message = r"Expected translation to end with: '\u00A0::'"
else:
fixed += " ::"
message = "Expected translation to end with: ' ::'"
if check and entry.msgstr != fixed:
print(f"{file}:{entry.linenum}: {message}")
has_errors = True
entry.msgstr = fixed
if not check:
pofile.save()
return has_errors