forked from AFPy/python-docs-fr
--check
This commit is contained in:
parent
763df12e5c
commit
0ae4d91abd
|
@ -1,3 +1,4 @@
|
||||||
|
import sys
|
||||||
import pathlib
|
import pathlib
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
|
|
||||||
|
@ -5,16 +6,31 @@ import polib
|
||||||
|
|
||||||
|
|
||||||
def check(file):
|
def check(file):
|
||||||
|
check = '--check' in sys.argv
|
||||||
pofile = polib.pofile(file)
|
pofile = polib.pofile(file)
|
||||||
|
has_errors = False
|
||||||
for entry in pofile:
|
for entry in pofile:
|
||||||
if not entry.msgstr:
|
if not entry.msgstr:
|
||||||
continue
|
continue
|
||||||
if entry.msgid.endswith(" ::"):
|
if entry.msgid.endswith(" ::"):
|
||||||
entry.msgstr = entry.msgstr.rstrip(": \u202f\u00A0") + " ::"
|
fixed = entry.msgstr.rstrip(": \u202f\u00A0") + " ::"
|
||||||
if entry.msgid.endswith("::") and not entry.msgid.endswith(" ::"):
|
if check and entry.msgstr != fixed:
|
||||||
entry.msgstr = entry.msgstr.rstrip(": ,. \u202f\u00A0") + "\u00A0::"
|
print(f"{file}:{entry.linenum}: Expected translation to end with: ' ::'")
|
||||||
pofile.save()
|
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")):
|
for file in chain(pathlib.Path(".").glob("*.po"), pathlib.Path(".").glob("*/*.po")):
|
||||||
check(file)
|
has_errors |= check(file)
|
||||||
|
|
||||||
|
sys.exit(has_errors)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user