Replaced old translator by the new yandex powered translator
This commit is contained in:
parent
2a5a184662
commit
92158f2496
@ -6,3 +6,4 @@ pypubsub==3.3.0
|
|||||||
requests-oauthlib
|
requests-oauthlib
|
||||||
future
|
future
|
||||||
arrow
|
arrow
|
||||||
|
yandex.translate
|
@ -55,9 +55,8 @@ class post(object):
|
|||||||
dlg = translator.gui.translateDialog()
|
dlg = translator.gui.translateDialog()
|
||||||
if dlg.get_response() == widgetUtils.OK:
|
if dlg.get_response() == widgetUtils.OK:
|
||||||
text_to_translate = self.message.get_text()
|
text_to_translate = self.message.get_text()
|
||||||
source = [x[0] for x in translator.translator.available_languages()][dlg.get("source_lang")]
|
|
||||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||||
msg = translator.translator.translate(text_to_translate, source, dest)
|
msg = translator.translator.translate(text_to_translate, dest)
|
||||||
self.message.set_text(msg)
|
self.message.set_text(msg)
|
||||||
self.message.text_focus()
|
self.message.text_focus()
|
||||||
output.speak(_(u"Translated"))
|
output.speak(_(u"Translated"))
|
||||||
|
@ -316,9 +316,8 @@ class postController(object):
|
|||||||
dlg = translator.gui.translateDialog()
|
dlg = translator.gui.translateDialog()
|
||||||
if dlg.get_response() == widgetUtils.OK:
|
if dlg.get_response() == widgetUtils.OK:
|
||||||
text_to_translate = self.dialog.post_view.GetValue().encode("utf-8")
|
text_to_translate = self.dialog.post_view.GetValue().encode("utf-8")
|
||||||
source = [x[0] for x in translator.translator.available_languages()][dlg.get("source_lang")]
|
|
||||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||||
msg = translator.translator.translate(text_to_translate, source, dest)
|
msg = translator.translator.translate(text_to_translate, target=dest)
|
||||||
self.dialog.post_view.ChangeValue(msg)
|
self.dialog.post_view.ChangeValue(msg)
|
||||||
output.speak(_(u"Translated"))
|
output.speak(_(u"Translated"))
|
||||||
else:
|
else:
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
#from microsofttranslator import Translator
|
from yandex_translate import YandexTranslate
|
||||||
|
|
||||||
def translate(text="", source="auto", target="en"):
|
|
||||||
t = Translator("twblue", "4KZA26GYIfmVAqQA/z16Hlucbg64hVSDTIpRjT2FqIU=")
|
|
||||||
return t.translate(text, target)
|
|
||||||
|
|
||||||
|
def translate(text="", target="en"):
|
||||||
|
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7")
|
||||||
|
vars = dict(text=text, lang=target)
|
||||||
|
return t.translate(**vars)["text"][0]
|
||||||
|
|
||||||
|
supported_langs = None
|
||||||
|
d = None
|
||||||
languages = {
|
languages = {
|
||||||
"af": _(u"Afrikaans"),
|
"af": _(u"Afrikaans"),
|
||||||
"sq": _(u"Albanian"),
|
"sq": _(u"Albanian"),
|
||||||
@ -71,7 +73,7 @@ languages = {
|
|||||||
"ps": _(u"Pashto"),
|
"ps": _(u"Pashto"),
|
||||||
"fa": _(u"Persian"),
|
"fa": _(u"Persian"),
|
||||||
"pl": _(u"Polish"),
|
"pl": _(u"Polish"),
|
||||||
"pt-PT": _(u"Portuguese"),
|
"pt": _(u"Portuguese"),
|
||||||
"pa": _(u"Punjabi"),
|
"pa": _(u"Punjabi"),
|
||||||
"ro": _(u"Romanian"),
|
"ro": _(u"Romanian"),
|
||||||
"ru": _(u"Russian"),
|
"ru": _(u"Russian"),
|
||||||
@ -101,8 +103,11 @@ languages = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def available_languages():
|
def available_languages():
|
||||||
l = languages.keys()
|
global supported_langs, d
|
||||||
d = languages.values()
|
if supported_langs == None and d == None:
|
||||||
l.insert(0, '')
|
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7")
|
||||||
d.insert(0, _(u"autodetect"))
|
supported_langs = t.langs
|
||||||
return sorted(zip(l, d))
|
d = []
|
||||||
|
for i in supported_langs:
|
||||||
|
d.append(languages[i])
|
||||||
|
return sorted(zip(supported_langs, d))
|
||||||
|
@ -18,28 +18,26 @@
|
|||||||
############################################################
|
############################################################
|
||||||
import translator
|
import translator
|
||||||
import wx
|
import wx
|
||||||
import widgetUtils
|
|
||||||
|
|
||||||
class translateDialog(widgetUtils.BaseDialog):
|
class translateDialog(wx.Dialog):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
|
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
|
||||||
panel = wx.Panel(self)
|
panel = wx.Panel(self)
|
||||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||||
staticSource = wx.StaticText(panel, -1, _(u"&Source language"))
|
staticDest = wx.StaticText(panel, -1, _(u"Target language"))
|
||||||
self.source_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
|
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
|
||||||
self.source_lang.SetFocus()
|
self.dest_lang.SetFocus()
|
||||||
staticDest = wx.StaticText(panel, -1, _(u"&Target language"))
|
self.dest_lang.SetSelection(0)
|
||||||
self.source_lang.SetSelection(0)
|
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||||
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
|
listSizer.Add(staticDest)
|
||||||
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
listSizer.Add(self.dest_lang)
|
||||||
listSizer.Add(staticSource)
|
ok = wx.Button(panel, wx.ID_OK)
|
||||||
listSizer.Add(self.source_lang)
|
ok.SetDefault()
|
||||||
listSizer.Add(staticDest)
|
cancel = wx.Button(panel, wx.ID_CANCEL)
|
||||||
listSizer.Add(self.dest_lang)
|
self.SetEscapeId(wx.ID_CANCEL)
|
||||||
ok = wx.Button(panel, wx.ID_OK)
|
|
||||||
ok.SetDefault()
|
|
||||||
cancel = wx.Button(panel, wx.ID_CANCEL)
|
|
||||||
self.SetEscapeId(wx.ID_CANCEL)
|
|
||||||
|
|
||||||
def get(self, control):
|
def get(self, control):
|
||||||
return getattr(self, control).GetSelection()
|
return getattr(self, control).GetSelection()
|
||||||
|
|
||||||
|
def get_response(self):
|
||||||
|
return self.ShowModal()
|
Loading…
Reference in New Issue
Block a user