From 9ed4b62df2446af83bfc8fc3db615581ebcee8a0 Mon Sep 17 00:00:00 2001
From: Yann Leboulanger <asterix@lagaule.org>
Date: Wed, 16 Nov 2011 17:52:19 +0100
Subject: [PATCH] make google translate plugin work when from language is
 "auto"

---
 plugins/google_translation/plugin.py | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/plugins/google_translation/plugin.py b/plugins/google_translation/plugin.py
index 4ff001e78c..dd1a155bad 100644
--- a/plugins/google_translation/plugin.py
+++ b/plugins/google_translation/plugin.py
@@ -129,7 +129,7 @@ class GoogleTranslationPlugin(GajimPlugin):
         self.controls = []
         self.translated_text_re = re.compile(
             r'google.language.callbacks.id100\(\'22\', '
-            '{"translatedText":"(?P<text>[^"]*)"}, 200, null, 200\)')
+            '{(?P<text>[^\}]*)}, 200, null, 200\)')
 
     @log_calls('GoogleTranslationPlugin')
     def translate_text(self, account, text, from_lang, to_lang):
@@ -146,7 +146,13 @@ class GoogleTranslationPlugin(GajimPlugin):
         if not results:
             return text
 
-        translated_text = self.translated_text_re.search(results).group('text')
+        result = self.translated_text_re.search(results)
+        if not result:
+            return text
+
+        dict_ = eval('{' + result.group('text') + '}')
+
+        translated_text = dict_.get('translatedText', '')
 
         if translated_text:
             try:
-- 
GitLab