Plugins/UiExtensionPlugins/Translator/TranslatorEngines/MicrosoftEngine.py

changeset 6470
5fe5ea985237
parent 6412
d71b094845e7
child 6645
ad476851d7e0
--- 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):

eric ide

mercurial