@@ -34,7 +34,9 @@ class LanguageTool:
3434 _instances = WeakValueDictionary ()
3535 _PORT_RE = re .compile (r"(?:https?://.*:|port\s+)(\d+)" , re .I )
3636
37- def __init__ (self , language = None , motherTongue = None , remote_server = None ):
37+ def __init__ (self , language = None , motherTongue = None , remote_server = None , newSpellings : List [str ] = None ):
38+ if newSpellings :
39+ self ._register_spellings (newSpellings )
3840 if remote_server is not None :
3941 self ._remote = True
4042 self ._url = parse_url (remote_server )
@@ -128,9 +130,12 @@ def disable_spellchecking(self):
128130 """Disable spell-checking rules."""
129131 self .disabled_categories .update (self ._spell_checking_categories )
130132
131- def register_spellings (self , spellings : List [str ]):
133+ def _register_spellings (self , spellings : List [str ]):
132134 library_path = get_language_tool_directory ()
133135 spelling_file_path = os .path .join (library_path , "org/languagetool/resource/en/hunspell/spelling.txt" )
136+ if not os .path .exists (spelling_file_path ):
137+ raise FileNotFoundError (f"Failed to find the spellings file at { spelling_file_path } \n "
138+ f"Please file an issue at https://github.com/jxmorris12/language_tool_python" )
134139 with open (spelling_file_path , "a+" ) as spellings_file :
135140 spellings_file .write ("\n " + "\n " .join ([word for word in spellings ]))
136141 print (f"Updated the spellings at { spelling_file_path } " )
0 commit comments