Colons checker in CI. #125

Merged
mdk merged 7 commits from mdk/python-docs-fr:mdk-colons into 3.11 2023-04-14 11:16:52 +00:00
1 changed files with 25 additions and 13 deletions
Showing only changes of commit d16166d2df - Show all commits

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