add --keep-capitalized argument
This commit is contained in:
parent
d724492c72
commit
d077fcfc67
23
pospell.py
23
pospell.py
|
@ -149,7 +149,7 @@ def clear(po_path, line, drop_capitalized=True):
|
|||
return regex.sub("|".join(to_drop), r"", line)
|
||||
|
||||
|
||||
def po_to_text(po_path):
|
||||
def po_to_text(po_path, drop_capitalized=True):
|
||||
"""Converts a po file to a text file, by stripping the msgids and all
|
||||
po syntax, but by keeping the kept lines at their same position /
|
||||
line number.
|
||||
|
@ -163,7 +163,7 @@ def po_to_text(po_path):
|
|||
while lines < entry.linenum:
|
||||
buffer.append("")
|
||||
lines += 1
|
||||
buffer.append(clear(po_path, strip_rst(entry.msgstr)))
|
||||
buffer.append(clear(po_path, strip_rst(entry.msgstr), drop_capitalized))
|
||||
lines += 1
|
||||
return "\n".join(buffer)
|
||||
|
||||
|
@ -190,6 +190,11 @@ def parse_args():
|
|||
help="Provide a glob pattern, to be interpreted by pospell, to find po files, "
|
||||
"like --glob '**/*.po'.",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--keep-capitalized",
|
||||
action="store_true",
|
||||
help="Do not drop capitalized words in sentences."
|
||||
)
|
||||
parser.add_argument(
|
||||
"po_file",
|
||||
nargs="*",
|
||||
|
@ -221,7 +226,7 @@ def parse_args():
|
|||
return args
|
||||
|
||||
|
||||
def spell_check(po_files, personal_dict, language, debug_only=False):
|
||||
def spell_check(po_files, personal_dict, language, drop_capitalized, debug_only=False):
|
||||
"""Check for spelling mistakes in the files po_files (po format,
|
||||
containing restructuredtext), for the given language.
|
||||
personal_dict allow to pass a personal dict (-p) option, to hunspell.
|
||||
|
@ -234,9 +239,9 @@ def spell_check(po_files, personal_dict, language, debug_only=False):
|
|||
tmpdir = Path(tmpdirname)
|
||||
for po_file in po_files:
|
||||
if debug_only:
|
||||
print(po_to_text(str(po_file)))
|
||||
print(po_to_text(str(po_file), drop_capitalized))
|
||||
continue
|
||||
(tmpdir / po_file.name).write_text(po_to_text(str(po_file)))
|
||||
(tmpdir / po_file.name).write_text(po_to_text(str(po_file), drop_capitalized))
|
||||
output = subprocess.check_output(
|
||||
["hunspell", "-d", language]
|
||||
+ personal_dict_arg
|
||||
|
@ -274,7 +279,13 @@ def main():
|
|||
for status, filename in git_status_lines
|
||||
if filename.endswith(".po")
|
||||
)
|
||||
errors = spell_check(args.po_file, args.personal_dict, args.language, args.debug)
|
||||
errors = spell_check(
|
||||
args.po_file,
|
||||
args.personal_dict,
|
||||
args.language,
|
||||
not args.keep_capitalized,
|
||||
args.debug,
|
||||
)
|
||||
exit(0 if errors == 0 else -1)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user