Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYann Leboulanger <asterix@lagaule.org>2011-11-16 23:11:25 +0400
committerYann Leboulanger <asterix@lagaule.org>2011-11-16 23:11:25 +0400
commit87504e39547d238c9f74e96564c258146359d114 (patch)
tree8d16df37f6f7f7fac93b200edc3c9c56dec0d5ab /plugins/google_translation/plugin.py
parent9ed4b62df2446af83bfc8fc3db615581ebcee8a0 (diff)
make google translation plugin work with unicode char
Diffstat (limited to 'plugins/google_translation/plugin.py')
-rw-r--r--plugins/google_translation/plugin.py23
1 files changed, 7 insertions, 16 deletions
diff --git a/plugins/google_translation/plugin.py b/plugins/google_translation/plugin.py
index dd1a155ba..1aa5ed111 100644
--- a/plugins/google_translation/plugin.py
+++ b/plugins/google_translation/plugin.py
@@ -26,12 +26,10 @@ Translates (currently only incoming) messages using Google Translate.
:license: GPL
'''
-import re
+import json
import urllib2
import HTMLParser
-import new
import gtk
-from pprint import pformat
from sys import getfilesystemencoding
import chat_control
@@ -43,7 +41,6 @@ from common import gajim
from plugins import GajimPlugin
from plugins.helpers import log_calls, log
from common import ged
-from common import nec
languages = {
_('Afrikaans'): 'af',
@@ -127,9 +124,6 @@ class GoogleTranslationPlugin(GajimPlugin):
}
self.controls = []
- self.translated_text_re = re.compile(
- r'google.language.callbacks.id100\(\'22\', '
- '{(?P<text>[^\}]*)}, 200, null, 200\)')
@log_calls('GoogleTranslationPlugin')
def translate_text(self, account, text, from_lang, to_lang):
@@ -137,8 +131,8 @@ class GoogleTranslationPlugin(GajimPlugin):
# Translate.
quoted_text = urllib2.quote(text.encode(getfilesystemencoding()))
# prepare url
- translation_url = u'http://www.google.com/uds/Gtranslate?callback='\
- 'google.language.callbacks.id100&context=22&q=%(quoted_text)s&'\
+ translation_url = u'https://ajax.googleapis.com/ajax/services/' \
+ 'language/translate?q=%(quoted_text)s&' \
'langpair=%(from_lang)s%%7C%(to_lang)s&key=notsupplied&v=1.0' % \
locals()
@@ -146,17 +140,14 @@ class GoogleTranslationPlugin(GajimPlugin):
if not results:
return text
- result = self.translated_text_re.search(results)
- if not result:
- return text
-
- dict_ = eval('{' + result.group('text') + '}')
+ result = json.loads(results)
- translated_text = dict_.get('translatedText', '')
+ if result.get('responseStatus', '') != 200:
+ return text
+ translated_text = result['responseData'].get('translatedText', '')
if translated_text:
try:
- translated_text = unicode(translated_text, 'unicode_escape')
htmlparser = HTMLParser.HTMLParser()
translated_text = htmlparser.unescape(translated_text)
except Exception: