From 0ae4d91abd08d75cb6f8b3d8035b8fcf8271ccc5 Mon Sep 17 00:00:00 2001 From: Julien Palard Date: Tue, 4 Apr 2023 09:24:19 +0200 Subject: [PATCH] --check --- .scripts/check-colon.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/.scripts/check-colon.py b/.scripts/check-colon.py index c02d4f4a..703a0871 100644 --- a/.scripts/check-colon.py +++ b/.scripts/check-colon.py @@ -1,3 +1,4 @@ +import sys import pathlib from itertools import chain @@ -5,16 +6,31 @@ import polib 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(" ::"): - entry.msgstr = entry.msgstr.rstrip(": \u202f\u00A0") + " ::" - if entry.msgid.endswith("::") and not entry.msgid.endswith(" ::"): - entry.msgstr = entry.msgstr.rstrip(": ,. \u202f\u00A0") + "\u00A0::" - pofile.save() + 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 + if not check: + pofile.save() + return has_errors +has_errors = False for file in chain(pathlib.Path(".").glob("*.po"), pathlib.Path(".").glob("*/*.po")): - check(file) + has_errors |= check(file) + +sys.exit(has_errors)