summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/.translate.py (renamed from plugins/translate.py)9
1 files changed, 5 insertions, 4 deletions
diff --git a/plugins/translate.py b/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()