forked from AFPy/python-docs-fr
Patch de ChrisNaN.
This commit is contained in:
parent
2e699f8734
commit
75170ed783
|
@ -1,7 +1,10 @@
|
|||
#!/usr/bin/env python
|
||||
"""Check consistency of colons at the end of entries.
|
||||
|
||||
It returns 0 if nothing was done, 1 if files were modified.
|
||||
"""
|
||||
import sys
|
||||
import pathlib
|
||||
from itertools import chain
|
||||
|
||||
import polib
|
||||
|
||||
|
||||
|
@ -15,7 +18,7 @@ def colon_is_visible(msg):
|
|||
raise ValueError("Don't know if msg ends with a visible or an invisible colon.")
|
||||
|
||||
|
||||
def fix_double_colon(entry, check):
|
||||
def fix_double_colon(filename, entry, check, verbose):
|
||||
fixed = entry.msgstr.rstrip(": \u202f\u00A0")
|
||||
if colon_is_visible(entry.msgid):
|
||||
fixed += "\u00A0::"
|
||||
|
@ -25,44 +28,78 @@ def fix_double_colon(entry, check):
|
|||
message = "Expected translation to end with: ' ::'"
|
||||
if entry.msgstr != fixed:
|
||||
if check:
|
||||
print(f"{file}:{entry.linenum}: {message}")
|
||||
print(f"{filename}:{entry.linenum}: {message}")
|
||||
if verbose:
|
||||
print(entry)
|
||||
else:
|
||||
entry.msgstr = fixed
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def fix_simple_colon(entry, check):
|
||||
def fix_simple_colon(filename, entry, check, verbose):
|
||||
fixed = entry.msgstr.rstrip(": \u202f\u00A0")
|
||||
fixed += "\u00A0:"
|
||||
if entry.msgstr != fixed:
|
||||
if check:
|
||||
print(fr"{file}:{entry.linenum}: Expected translation to end with: '\u00A0:'")
|
||||
print(
|
||||
rf"{filename}:{entry.linenum}: Expected translation to end with: '\u00A0:'"
|
||||
)
|
||||
if verbose:
|
||||
print(entry)
|
||||
else:
|
||||
entry.msgstr = fixed
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def check(file):
|
||||
check = '--check' in sys.argv
|
||||
pofile = polib.pofile(file)
|
||||
def check(filename, check, verbose):
|
||||
try:
|
||||
pofile = polib.pofile(filename)
|
||||
except OSError:
|
||||
print(f"{filename} doesn't seem to be a .po file", file=sys.stderr)
|
||||
return True
|
||||
has_errors = False
|
||||
for entry in pofile:
|
||||
if not entry.msgstr:
|
||||
continue # No need to check untranslated entries.
|
||||
if entry.msgid.endswith("::"):
|
||||
has_errors |= fix_double_colon(entry, check)
|
||||
has_errors |= fix_double_colon(filename, entry, check, verbose)
|
||||
elif entry.msgid.endswith(":"):
|
||||
has_errors |= fix_simple_colon(entry, check)
|
||||
has_errors |= fix_simple_colon(filename, entry, check, verbose)
|
||||
|
||||
if not check and has_errors:
|
||||
pofile.save()
|
||||
return has_errors
|
||||
|
||||
|
||||
has_errors = False
|
||||
for file in chain(pathlib.Path(".").glob("*.po"), pathlib.Path(".").glob("*/*.po")):
|
||||
has_errors |= check(file)
|
||||
def parse_args():
|
||||
import argparse
|
||||
|
||||
sys.exit(has_errors)
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--check",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="only display suspected entries, do not fix.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--verbose",
|
||||
action="store_true",
|
||||
default=False,
|
||||
help="display whole entry",
|
||||
)
|
||||
parser.add_argument("path", nargs="*")
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
def main():
|
||||
has_errors = False
|
||||
args = parse_args()
|
||||
for filename in args.path:
|
||||
has_errors |= check(filename, args.check, args.verbose)
|
||||
sys.exit(has_errors)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
7
Makefile
7
Makefile
|
@ -149,7 +149,7 @@ spell: ensure_test_prerequisites $(DESTS)
|
|||
|
||||
.PHONY: line-length
|
||||
line-length:
|
||||
@echo "Searching for long lines..."
|
||||
@echo "Checking all files using .scripts/line-length.py..."
|
||||
@python .scripts/line-length.py *.po */*.po
|
||||
|
||||
.PHONY: sphinx-lint
|
||||
|
@ -187,10 +187,11 @@ check-headers:
|
|||
|
||||
.PHONY: check-colons
|
||||
check-colons:
|
||||
@python .scripts/check-colon.py --check
|
||||
@echo "Checking all files using .scripts/check-colon.py..."
|
||||
@python .scripts/check-colon.py --check *.po */*.po
|
||||
|
||||
.PHONY: verifs
|
||||
verifs: spell line-length sphinx-lint check-headers check-colons
|
||||
verifs: spell line-length check-headers check-colons sphinx-lint
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
|
|
|
@ -7,7 +7,7 @@ msgstr ""
|
|||
"Project-Id-Version: Python 3\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2023-02-12 11:56+0100\n"
|
||||
"PO-Revision-Date: 2023-04-10 16:56+0200\n"
|
||||
"PO-Revision-Date: 2023-04-10 22:32+0200\n"
|
||||
"Last-Translator: Loc Cosnier <loc.cosnier@pm.me>\n"
|
||||
"Language-Team: FRENCH <traductions@lists.afpy.org>\n"
|
||||
"Language: fr\n"
|
||||
|
@ -18,7 +18,6 @@ msgstr ""
|
|||
"X-Generator: Poedit 3.2.1\n"
|
||||
|
||||
|
||||
|
||||
#: library/stdtypes.rst:8
|
||||
msgid "Built-in Types"
|
||||
msgstr "Types natifs"
|
||||
|
|
Loading…
Reference in New Issue