From e1a817607b56c2cdb116b5ef55e17e8d856b10e5 Mon Sep 17 00:00:00 2001 From: mathieui Date: Wed, 9 May 2012 19:19:17 +0200 Subject: [PATCH] Make translate.py more customizable, and hide it for now --- plugins/{translate.py => .translate.py} | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) rename plugins/{translate.py => .translate.py} (77%) diff --git a/plugins/translate.py b/plugins/.translate.py similarity index 77% rename from plugins/translate.py rename to plugins/.translate.py index 520d02b4..af252a4e 100644 --- a/plugins/translate.py +++ b/plugins/.translate.py @@ -7,7 +7,7 @@ import json TARGET_LANG = 'en' def translate(s, target=TARGET_LANG, source=''): - f = urllib.request.urlopen('http://ajax.googleapis.com/ajax/services/language/translate', urlencode({ 'v': '1.0', 'q': s, 'langpair': '%s|%s' % (source, target) })) + f = urllib.request.urlopen('http://ajax.googleapis.com/ajax/services/language/translate', urlencode({ 'v': '1.0', 'q': s, 'langpair': '%s|%s' % (source, target) }).encode('utf-8')) response = json.loads(str(f.read(), 'utf-8'))['responseData'] return (response['translatedText'], response['detectedSourceLanguage']) @@ -21,11 +21,12 @@ class Plugin(BasePlugin): if message['type'] == 'error': return - if room_from == 'poezio@muc.poezio.eu': + if room_from in self.config.options(): + target_lang = self.config.get(room_from, self.config.get('default', TARGET_LANG)) nick_from = message['mucnick'] body = xhtml.get_body_from_message_stanza(message) - room = self.core.get_room_by_name(room_from) - text, lang = translate(body) + room = self.core.get_tab_by_name(room_from) + text, lang = translate(body, target=target_lang) if lang != TARGET_LANG: room.add_message(text, nickname=nick_from) self.core.refresh_window()