From eea26ec7b075d554c19b6fd96140c8b7f2ead375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Golonka?= Date: Tue, 20 Jul 2021 19:00:31 +0200 Subject: [PATCH] Fix plugin failing to initialize when NVDA was set to language for which there is no Tesseract data --- addon/globalPlugins/ocr.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/addon/globalPlugins/ocr.py b/addon/globalPlugins/ocr.py index b0cc241..018714f 100644 --- a/addon/globalPlugins/ocr.py +++ b/addon/globalPlugins/ocr.py @@ -40,7 +40,7 @@ class LanguageInfo: """Provides information about a single language supported by Tesseract.""" # Tesseract identifies languages using their ISO 639-2 language codes - # whereas NVDA locales are identifed by ISO 639-1 codes. + # whereas NVDA locales are identified by ISO 639-1 codes. # Below dictionaries provide mapping from one representation to the other. NVDALocalesToTesseractLangs = { "bg": "bul", @@ -126,11 +126,12 @@ def fromFallbackLanguage(cls): @classmethod def fromCurrentNVDALanguage(cls): currentNVDALang = languageHandler.getLanguage() - for possibleLocaleName in (currentNVDALang, currentNVDALang.split("_")[0], cls.FALLBACK_LANGUAGE): + for possibleLocaleName in (currentNVDALang, currentNVDALang.split("_")[0]): try: return cls(NVDALocaleName=possibleLocaleName) except KeyError: continue + return cls.fromFallbackLanguage() @property def localizedName(self):