update google_translation plugin to py3
This commit is contained in:
@@ -1 +1 @@
|
|||||||
from plugin import GoogleTranslationPlugin
|
from .plugin import GoogleTranslationPlugin
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ name: Google Translation
|
|||||||
short_name: google_translation
|
short_name: google_translation
|
||||||
version: 0.3.2
|
version: 0.3.2
|
||||||
description: Translates (currently only incoming) messages using Google Translate.
|
description: Translates (currently only incoming) messages using Google Translate.
|
||||||
authors = Mateusz Biliński <mateusz@bilinski.it>
|
authors: Mateusz Biliński <mateusz@bilinski.it>
|
||||||
mrDoctorWho <mrdoctorwho@gmail.com>
|
mrDoctorWho <mrdoctorwho@gmail.com>
|
||||||
homepage = http://trac-plugins.gajim.org/wiki/GoogleTranslationPlugin
|
homepage: http://trac-plugins.gajim.org/wiki/GoogleTranslationPlugin
|
||||||
max_gajim_version: 0.15.9
|
min_gajim_version: 0.15.10
|
||||||
|
|||||||
@@ -29,9 +29,7 @@ Translates (currently only incoming) messages using Google Translate.
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
from gi.repository import Gtk
|
||||||
import HTMLParser
|
|
||||||
import gtk
|
|
||||||
from sys import getfilesystemencoding
|
from sys import getfilesystemencoding
|
||||||
|
|
||||||
import chat_control
|
import chat_control
|
||||||
@@ -132,15 +130,15 @@ class GoogleTranslationPlugin(GajimPlugin):
|
|||||||
data = {"client": "x",
|
data = {"client": "x",
|
||||||
"tl": to_lang,
|
"tl": to_lang,
|
||||||
"sl": from_lang,
|
"sl": from_lang,
|
||||||
"text": text.encode("utf-8")}
|
"text": text}
|
||||||
url = "http://translate.google.ru/translate_a/t"
|
url = "http://translate.google.ru/translate_a/t"
|
||||||
url = u"%s?%s" % (url, urllib.urlencode(data))
|
url = "%s?%s" % (url, urllib.parse.urlencode(data))
|
||||||
request = urllib2.Request(url)
|
request = urllib.request.Request(url)
|
||||||
request.add_header("User-Agent",
|
request.add_header("User-Agent",
|
||||||
"Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20120815 Firefox/16.0")
|
"Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20120815 Firefox/16.0")
|
||||||
response = urllib2.urlopen(request)
|
response = urllib.request.urlopen(request).read().decode('utf-8')
|
||||||
if response:
|
if response:
|
||||||
data = json.load(response)
|
data = json.loads(response)
|
||||||
return data["sentences"][0]["trans"]
|
return data["sentences"][0]["trans"]
|
||||||
return text
|
return text
|
||||||
|
|
||||||
@@ -200,19 +198,19 @@ class Base(object):
|
|||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
self.expander = gtk.Expander(_('Google translation'))
|
self.expander = Gtk.Expander(label=_('Google translation'))
|
||||||
hbox = gtk.HBox(spacing=6)
|
hbox = Gtk.HBox(spacing=6)
|
||||||
self.expander.add(hbox)
|
self.expander.add(hbox)
|
||||||
label = gtk.Label(_('Translate from'))
|
label = Gtk.Label(_('Translate from'))
|
||||||
hbox.pack_start(label, False, False)
|
hbox.pack_start(label, False, False, 0)
|
||||||
liststore1 = gtk.ListStore(str, str)
|
liststore1 = Gtk.ListStore(str, str)
|
||||||
liststore2 = gtk.ListStore(str, str)
|
liststore2 = Gtk.ListStore(str, str)
|
||||||
cb1 = gtk.ComboBox(liststore1)
|
cb1 = Gtk.ComboBox.new_with_model(liststore1)
|
||||||
cb2 = gtk.ComboBox(liststore2)
|
cb2 = Gtk.ComboBox.new_with_model(liststore2)
|
||||||
cell = gtk.CellRendererText()
|
cell = Gtk.CellRendererText()
|
||||||
cb1.pack_start(cell, True)
|
cb1.pack_start(cell, True)
|
||||||
cb1.add_attribute(cell, 'text', 0)
|
cb1.add_attribute(cell, 'text', 0)
|
||||||
cell = gtk.CellRendererText()
|
cell = Gtk.CellRendererText()
|
||||||
cb2.pack_start(cell, True)
|
cb2.pack_start(cell, True)
|
||||||
cb2.add_attribute(cell, 'text', 0)
|
cb2.add_attribute(cell, 'text', 0)
|
||||||
#Language to translate from
|
#Language to translate from
|
||||||
@@ -222,8 +220,7 @@ class Base(object):
|
|||||||
if self.config['from'] == '':
|
if self.config['from'] == '':
|
||||||
cb1.set_active(0)
|
cb1.set_active(0)
|
||||||
i = 0
|
i = 0
|
||||||
ls = languages.items()
|
ls = sorted(languages.items())
|
||||||
ls.sort()
|
|
||||||
for l in ls:
|
for l in ls:
|
||||||
liststore1.append(l)
|
liststore1.append(l)
|
||||||
if l[1] == self.config['from']:
|
if l[1] == self.config['from']:
|
||||||
@@ -233,16 +230,16 @@ class Base(object):
|
|||||||
cb2.set_active(i)
|
cb2.set_active(i)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
hbox.pack_start(cb1, False, False)
|
hbox.pack_start(cb1, False, False, 0)
|
||||||
label = gtk.Label(_('to'))
|
label = Gtk.Label(_('to'))
|
||||||
hbox.pack_start(label, False, False)
|
hbox.pack_start(label, False, False, 0)
|
||||||
hbox.pack_start(cb2, False, False)
|
hbox.pack_start(cb2, False, False, 0)
|
||||||
|
|
||||||
cb = gtk.CheckButton(_('enable'))
|
cb = Gtk.CheckButton(_('enable'))
|
||||||
if self.config['enabled']:
|
if self.config['enabled']:
|
||||||
cb.set_active(True)
|
cb.set_active(True)
|
||||||
hbox.pack_start(cb, False, False)
|
hbox.pack_start(cb, False, False, 0)
|
||||||
vbox.pack_start(self.expander, False, False)
|
vbox.pack_start(self.expander, False, False, 0)
|
||||||
vbox.reorder_child(self.expander, 1)
|
vbox.reorder_child(self.expander, 1)
|
||||||
|
|
||||||
cb1.connect('changed', self.on_cb_changed, 'from')
|
cb1.connect('changed', self.on_cb_changed, 'from')
|
||||||
|
|||||||
Reference in New Issue
Block a user