Skip to content
This repository has been archived by the owner on Mar 10, 2023. It is now read-only.

Commit

Permalink
FIX: Sync error due to line seen as commented by hunspell.
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienPalard committed Oct 13, 2020
1 parent 1024612 commit e9bdc84
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pospell.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,18 @@ def clear(line, drop_capitalized=False, po_path=""):
return regex.sub("|".join(to_drop), r" ", line)


def quote_for_hunspell(text):
"""
Quoting the manpage:
It is recommended that programmatic interfaces prefix
every data line with an uparrow to protect themselves
against future changes in hunspell."""
out = []
for line in text.split("\n"):
out.append("^" + line if line else "")
return "\n".join(out)


def po_to_text(po_path, drop_capitalized=False):
"""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 /
Expand Down Expand Up @@ -295,7 +307,7 @@ def spell_check(
output = subprocess.run(
["hunspell", "-d", language, "-a"] + personal_dict_arg,
universal_newlines=True,
input="\n".join(texts_for_hunspell.values()),
input=quote_for_hunspell("\n".join(texts_for_hunspell.values())),
stdout=subprocess.PIPE,
)
except subprocess.CalledProcessError:
Expand Down

0 comments on commit e9bdc84

Please sign in to comment.