summaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2012-05-09 19:19:17 +0200
committermathieui <mathieui@mathieui.net>2012-05-09 19:19:17 +0200
commite1a817607b56c2cdb116b5ef55e17e8d856b10e5 (patch)
tree017ea53d2a19eb30b62501736fbdfca8be5d9ca2 /plugins
parent5c327ef232522a637c3ea1960569dac697865996 (diff)
downloadpoezio-e1a817607b56c2cdb116b5ef55e17e8d856b10e5.tar.gz
poezio-e1a817607b56c2cdb116b5ef55e17e8d856b10e5.tar.bz2
poezio-e1a817607b56c2cdb116b5ef55e17e8d856b10e5.tar.xz
poezio-e1a817607b56c2cdb116b5ef55e17e8d856b10e5.zip
Make translate.py more customizable, and hide it for now
Diffstat (limited to 'plugins')
-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()