From 1beb8a49c4b89e0adfab37cc4b44eec121202fe6 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Tue, 29 Oct 2019 22:19:05 +0100 Subject: [PATCH] Added a dummy spell check class in case loading one fails --- nw/tools/spellenchant.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/nw/tools/spellenchant.py b/nw/tools/spellenchant.py index 4b56238d..b2faa472 100644 --- a/nw/tools/spellenchant.py +++ b/nw/tools/spellenchant.py @@ -32,6 +32,9 @@ class NWSpellEnchant(NWSpellCheck): return def setLanguage(self, theLang, projectDict=None): + """Load a dictionary for the language specified in the config. If that fails, we load a + dummy dictionary so that lookups don't crash. + """ try: if projectDict is None: self.theDict = enchant.Dict(theLang) @@ -40,7 +43,8 @@ class NWSpellEnchant(NWSpellCheck): logger.debug("Enchant spell checking for language %s loaded" % theLang) except: logger.error("Failed to load enchant spell checking for language %s" % theLang) - self.theDict = None + self.theDict = NWSpellEnchantDummy() + return def checkWord(self, theWord): @@ -73,3 +77,19 @@ class NWSpellEnchant(NWSpellCheck): return retList # END Class NWSpellEnchant + +class NWSpellEnchantDummy: + + def __init__(self): + return + + def check(self, theWord): + return True + + def suggest(self, theWord): + return [] + + def add_to_pwl(self, theWord): + return + +# END Class NWSpellEnchantDummy