Skip to content

Commit 1809abf

Browse files
author
Brian Merchant
authored
Allow handling of utf-8 encoded files
Currently, if you try to register a word like "Walchaís" (not accent on i) with `language_tool_python`, so that it is ignored in spell check, we get a Unicode encoding error. This can be fixed by letting the functions which read/write custom spellings: `_register_spellings` and `_unregister_spellings`. We could improve this by letting these functions take a variable called `encoding`.
1 parent 424b2a6 commit 1809abf

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎language_tool_python/server.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ def _get_valid_spelling_file_path() -> str:
150150

151151
def _register_spellings(self, spellings):
152152
spelling_file_path = self._get_valid_spelling_file_path()
153-
with open(spelling_file_path, "a+") as spellings_file:
153+
with open(spelling_file_path, "a+", encoding='utf-8') as spellings_file:
154154
spellings_file.write("\n" + "\n".join([word for word in spellings]))
155155
if DEBUG_MODE:
156156
print("Registered new spellings at {}".format(spelling_file_path))
157157

158158
def _unregister_spellings(self):
159159
spelling_file_path = self._get_valid_spelling_file_path()
160-
with open(spelling_file_path, 'r+') as spellings_file:
160+
with open(spelling_file_path, 'r+', encoding='utf-8') as spellings_file:
161161
spellings_file.seek(0, os.SEEK_END)
162162
for _ in range(len(self._new_spellings)):
163163
while spellings_file.read(1) != '\n':

0 commit comments

Comments
 (0)