Tue, 21 Aug 2018 11:43:00 +0200
TranslatorEngines: fixed an issue in some translator engines not respecting the possibility of receiving an error string object from the TranslatorObject.get() call.
--- a/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/GlosbeEngine.py Mon Aug 13 16:46:25 2018 +0200 +++ b/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/GlosbeEngine.py Tue Aug 21 11:43:00 2018 +0200 @@ -82,8 +82,8 @@ text) url = QUrl(self.TranslatorUrl + params) response, ok = requestObject.get(url) - response = str(response, "utf-8", "replace") if ok: + response = str(response, "utf-8", "replace") try: responseDict = json.loads(response) except ValueError:
--- a/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/GoogleV2Engine.py Mon Aug 13 16:46:25 2018 +0200 +++ b/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/GoogleV2Engine.py Tue Aug 21 11:43:00 2018 +0200 @@ -76,8 +76,8 @@ originalLanguage, translationLanguage, text, apiKey) url = QUrl(self.TranslatorUrl + params) response, ok = requestObject.get(url) - response = str(response, "utf-8", "replace") if ok: + response = str(response, "utf-8", "replace") try: responseDict = json.loads(response) except ValueError:
--- a/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/MicrosoftEngine.py Mon Aug 13 16:46:25 2018 +0200 +++ b/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/MicrosoftEngine.py Tue Aug 21 11:43:00 2018 +0200 @@ -161,13 +161,14 @@ text) url = QUrl(self.TranslatorUrl + params) response, ok = requestObject.get(url, extraHeaders=[authHeader]) - response = str(response, "utf-8", "replace") - if ok and response.startswith("<string") and \ - response.endswith("</string>"): - result = response.split(">", 1)[1].rsplit("<", 1)[0] - else: - result = self.tr("No translation available.") - ok = False + if ok: + response = str(response, "utf-8", "replace").strip() + if response.startswith("<string") and \ + response.endswith("</string>"): + result = response.split(">", 1)[1].rsplit("<", 1)[0] + else: + result = self.tr("No translation available.") + ok = False return result, ok def getTextToSpeechData(self, requestObject, text, language):
--- a/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/MyMemoryEngine.py Mon Aug 13 16:46:25 2018 +0200 +++ b/Plugins/UiExtensionPlugins/Translator/TranslatorEngines/MyMemoryEngine.py Tue Aug 21 11:43:00 2018 +0200 @@ -92,8 +92,8 @@ keyParam, emailParam) url = QUrl(self.TranslatorUrl + params) response, ok = requestObject.get(url) - response = str(response, "utf-8", "replace") if ok: + response = str(response, "utf-8", "replace") try: responseDict = json.loads(response) except ValueError: