From 7fcd0731bfc01b328bc3b8331a42e2349b5d5117 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" <1619840+vkbo@users.noreply.github.com> Date: Fri, 8 Nov 2019 19:56:08 +0100 Subject: [PATCH] Added a function to create a readable spell language string for the status bar --- nw/tools/spellcheck.py | 13 +++++++++++++ nw/tools/spellenchant.py | 11 +---------- nw/tools/spellsimple.py | 14 ++------------ 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/nw/tools/spellcheck.py b/nw/tools/spellcheck.py index 94227b29..fd5142c8 100644 --- a/nw/tools/spellcheck.py +++ b/nw/tools/spellcheck.py @@ -13,6 +13,8 @@ import logging import nw +from nw.constants import isoLanguage + logger = logging.getLogger(__name__) class NWSpellCheck(): @@ -54,6 +56,17 @@ class NWSpellCheck(): def listDictionaries(self): return [] + @staticmethod + def expandLanguage(spTag): + spBits = spTag.split("_") + if spBits[0] in isoLanguage.ISO_639_1: + spLang = isoLanguage.ISO_639_1[spBits[0]] + else: + spLang = spBits[0] + if len(spBits) > 1: + spLang += " (%s)" % spBits[1] + return spLang + ## # Internal Functions ## diff --git a/nw/tools/spellenchant.py b/nw/tools/spellenchant.py index e4116580..1bff2329 100644 --- a/nw/tools/spellenchant.py +++ b/nw/tools/spellenchant.py @@ -15,7 +15,6 @@ import enchant import nw from nw.tools.spellcheck import NWSpellCheck -from nw.constants import isoLanguage logger = logging.getLogger(__name__) @@ -58,15 +57,7 @@ class NWSpellEnchant(NWSpellCheck): def listDictionaries(self): retList = [] for spTag, spProvider in enchant.list_dicts(): - spList = [] - if spTag[:2] in isoLanguage.ISO_639_1: - spList.append(isoLanguage.ISO_639_1[spTag[:2]]) - else: - spList.append(spTag[:2]) - if len(spTag) > 3: - spList.append("(%s)" % spTag[3:]) - spList.append("[%s]" % spProvider.name) - spName = " ".join(spList) + spName = "%s [%s]" % (self.expandLanguage(spTag), spProvider.name) retList.append((spTag, spName)) return retList diff --git a/nw/tools/spellsimple.py b/nw/tools/spellsimple.py index db7c38af..d98947e5 100644 --- a/nw/tools/spellsimple.py +++ b/nw/tools/spellsimple.py @@ -19,7 +19,6 @@ from difflib import get_close_matches logger = logging.getLogger(__name__) from nw.tools.spellcheck import NWSpellCheck -from nw.constants import isoLanguage class NWSpellSimple(NWSpellCheck): @@ -105,17 +104,8 @@ class NWSpellSimple(NWSpellCheck): if theBits[1] != ".dict": continue - spTag = theBits[0] - spList = [] - if spTag[:2] in isoLanguage.ISO_639_1: - spList.append(isoLanguage.ISO_639_1[spTag[:2]]) - else: - spList.append(spTag[:2]) - if len(spTag) > 3: - spList.append("(%s)" % spTag[3:]) - spList.append("[internal]") - spName = " ".join(spList) - retList.append((spTag, spName)) + spName = "%s [nternal]" % self.expandLanguage(theBits[0]) + retList.append((theBits[0], spName)) return retList