Skip to content

Commit 57b12b2

Browse files
committed
Add function to register new spellings. This is useful when deploying in unique scenarios.
1 parent cd8ec98 commit 57b12b2

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎language_tool_python/server.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import socket
66
import threading
77
import urllib.parse
8+
from typing import List
89
from weakref import WeakValueDictionary
910
from .download_lt import download_lt
1011
from .language_tag import LanguageTag
@@ -127,6 +128,13 @@ def disable_spellchecking(self):
127128
"""Disable spell-checking rules."""
128129
self.disabled_categories.update(self._spell_checking_categories)
129130

131+
def register_spellings(self, spellings: List[str]):
132+
library_path = get_language_tool_directory()
133+
spelling_file_path = os.path.join(library_path, "org/languagetool/resource/en/hunspell/spelling.txt")
134+
with open(spelling_file_path, "a+") as spellings_file:
135+
spellings_file.write("\n" + "\n".join([word for word in spellings]))
136+
print(f"Updated the spellings at {spelling_file_path}")
137+
130138
def _get_languages(self) -> set:
131139
"""Get supported languages (by querying the server)."""
132140
self._start_server_if_needed()

0 commit comments

Comments
 (0)