Changed translation service to google Translate
This commit is contained in:
parent
b8ef10af3f
commit
273f25c24f
@ -10,11 +10,13 @@
|
||||
|
||||
* Now it is possible to perform authentication in accounts using two factor verification again. This issue was caused due to a recent change in the VK workflow for two factor verification processes.
|
||||
* Users who have chosen to not show their online activity (specifically the last seen field in VK) will be added in people buffers. Before, those people were making socializer to raise an exception and the whole buffer was unable to be loaded.
|
||||
* It is possible to translate texts again, thanks to the Google Translate implementation added in the application.
|
||||
|
||||
### Changes
|
||||
|
||||
* The spelling correction module has been rewritten to take advantage of the newest enchant Python module which is more stable and can be added properly to the distribution, as opposed to the first enchant module we have tried.
|
||||
* Better performance on Socializer should be noticed for users with many conversations opened. Before, socializer could freeze while loading all messages in conversations. Now that should work more efficiently and the application should not stop responding.
|
||||
* Socializer now uses Google Translate services instead of yandex.translate.
|
||||
|
||||
## News in Version 0.24
|
||||
|
||||
|
@ -9,7 +9,6 @@ requests-oauthlib
|
||||
future
|
||||
arrow
|
||||
backports.functools_lru_cache
|
||||
yandex.translate
|
||||
googletrans
|
||||
mutagen
|
||||
mock
|
||||
|
@ -1,6 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import platform
|
||||
from . import translator
|
||||
if platform.system() == "Windows":
|
||||
from . import wx_ui as gui
|
||||
|
||||
from . import translator
|
@ -1,115 +1,116 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
from builtins import zip
|
||||
from yandex_translate import YandexTranslate
|
||||
import logging
|
||||
from googletrans import Translator, LANGUAGES
|
||||
|
||||
log = logging.getLogger("extras.translator")
|
||||
|
||||
# create a single translator instance
|
||||
# see https://github.com/ssut/py-googletrans/issues/234
|
||||
t = None
|
||||
|
||||
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]
|
||||
global t
|
||||
log.debug("Received translation request for language %s, text=%s" % (target, text))
|
||||
if t == None:
|
||||
t = Translator()
|
||||
vars = dict(text=text, dest=target)
|
||||
return t.translate(**vars).text
|
||||
|
||||
supported_langs = None
|
||||
d = None
|
||||
|
||||
languages = {
|
||||
"af": _("Afrikaans"),
|
||||
"sq": _("Albanian"),
|
||||
"am": _("Amharic"),
|
||||
"ar": _("Arabic"),
|
||||
"hy": _("Armenian"),
|
||||
"az": _("Azerbaijani"),
|
||||
"eu": _("Basque"),
|
||||
"be": _("Belarusian"),
|
||||
"bn": _("Bengali"),
|
||||
"bh": _("Bihari"),
|
||||
"bg": _("Bulgarian"),
|
||||
"my": _("Burmese"),
|
||||
"ca": _("Catalan"),
|
||||
"chr": _("Cherokee"),
|
||||
"zh": _("Chinese"),
|
||||
"zh-CN": _("Chinese_simplified"),
|
||||
"zh-TW": _("Chinese_traditional"),
|
||||
"hr": _("Croatian"),
|
||||
"cs": _("Czech"),
|
||||
"da": _("Danish"),
|
||||
"dv": _("Dhivehi"),
|
||||
"nl": _("Dutch"),
|
||||
"en": _("English"),
|
||||
"eo": _("Esperanto"),
|
||||
"et": _("Estonian"),
|
||||
"tl": _("Filipino"),
|
||||
"fi": _("Finnish"),
|
||||
"fr": _("French"),
|
||||
"gl": _("Galician"),
|
||||
"ka": _("Georgian"),
|
||||
"de": _("German"),
|
||||
"el": _("Greek"),
|
||||
"gn": _("Guarani"),
|
||||
"gu": _("Gujarati"),
|
||||
"iw": _("Hebrew"),
|
||||
"hi": _("Hindi"),
|
||||
"hu": _("Hungarian"),
|
||||
"is": _("Icelandic"),
|
||||
"id": _("Indonesian"),
|
||||
"iu": _("Inuktitut"),
|
||||
"ga": _("Irish"),
|
||||
"it": _("Italian"),
|
||||
"ja": _("Japanese"),
|
||||
"kn": _("Kannada"),
|
||||
"kk": _("Kazakh"),
|
||||
"km": _("Khmer"),
|
||||
"ko": _("Korean"),
|
||||
"ku": _("Kurdish"),
|
||||
"ky": _("Kyrgyz"),
|
||||
"lo": _("Laothian"),
|
||||
"lv": _("Latvian"),
|
||||
"lt": _("Lithuanian"),
|
||||
"mk": _("Macedonian"),
|
||||
"ms": _("Malay"),
|
||||
"ml": _("Malayalam"),
|
||||
"mt": _("Maltese"),
|
||||
"mr": _("Marathi"),
|
||||
"mn": _("Mongolian"),
|
||||
"ne": _("Nepali"),
|
||||
"no": _("Norwegian"),
|
||||
"or": _("Oriya"),
|
||||
"ps": _("Pashto"),
|
||||
"fa": _("Persian"),
|
||||
"pl": _("Polish"),
|
||||
"pt": _("Portuguese"),
|
||||
"pa": _("Punjabi"),
|
||||
"ro": _("Romanian"),
|
||||
"ru": _("Russian"),
|
||||
"sa": _("Sanskrit"),
|
||||
"sr": _("Serbian"),
|
||||
"sd": _("Sindhi"),
|
||||
"si": _("Sinhalese"),
|
||||
"sk": _("Slovak"),
|
||||
"sl": _("Slovenian"),
|
||||
"es": _("Spanish"),
|
||||
"sw": _("Swahili"),
|
||||
"sv": _("Swedish"),
|
||||
"tg": _("Tajik"),
|
||||
"ta": _("Tamil"),
|
||||
"tl": _("Tagalog"),
|
||||
"te": _("Telugu"),
|
||||
"th": _("Thai"),
|
||||
"bo": _("Tibetan"),
|
||||
"tr": _("Turkish"),
|
||||
"uk": _("Ukrainian"),
|
||||
"ur": _("Urdu"),
|
||||
"uz": _("Uzbek"),
|
||||
"ug": _("Uighur"),
|
||||
"vi": _("Vietnamese"),
|
||||
"cy": _("Welsh"),
|
||||
"yi": _("Yiddish")
|
||||
"af": _(u"Afrikaans"),
|
||||
"sq": _(u"Albanian"),
|
||||
"am": _(u"Amharic"),
|
||||
"ar": _(u"Arabic"),
|
||||
"hy": _(u"Armenian"),
|
||||
"az": _(u"Azerbaijani"),
|
||||
"eu": _(u"Basque"),
|
||||
"be": _(u"Belarusian"),
|
||||
"bn": _(u"Bengali"),
|
||||
"bh": _(u"Bihari"),
|
||||
"bg": _(u"Bulgarian"),
|
||||
"my": _(u"Burmese"),
|
||||
"ca": _(u"Catalan"),
|
||||
"chr": _(u"Cherokee"),
|
||||
"zh": _(u"Chinese"),
|
||||
"zh-CN": _(u"Chinese_simplified"),
|
||||
"zh-TW": _(u"Chinese_traditional"),
|
||||
"hr": _(u"Croatian"),
|
||||
"cs": _(u"Czech"),
|
||||
"da": _(u"Danish"),
|
||||
"dv": _(u"Dhivehi"),
|
||||
"nl": _(u"Dutch"),
|
||||
"en": _(u"English"),
|
||||
"eo": _(u"Esperanto"),
|
||||
"et": _(u"Estonian"),
|
||||
"tl": _(u"Filipino"),
|
||||
"fi": _(u"Finnish"),
|
||||
"fr": _(u"French"),
|
||||
"gl": _(u"Galician"),
|
||||
"ka": _(u"Georgian"),
|
||||
"de": _(u"German"),
|
||||
"el": _(u"Greek"),
|
||||
"gn": _(u"Guarani"),
|
||||
"gu": _(u"Gujarati"),
|
||||
"iw": _(u"Hebrew"),
|
||||
"hi": _(u"Hindi"),
|
||||
"hu": _(u"Hungarian"),
|
||||
"is": _(u"Icelandic"),
|
||||
"id": _(u"Indonesian"),
|
||||
"iu": _(u"Inuktitut"),
|
||||
"ga": _(u"Irish"),
|
||||
"it": _(u"Italian"),
|
||||
"ja": _(u"Japanese"),
|
||||
"kn": _(u"Kannada"),
|
||||
"kk": _(u"Kazakh"),
|
||||
"km": _(u"Khmer"),
|
||||
"ko": _(u"Korean"),
|
||||
"ku": _(u"Kurdish"),
|
||||
"ky": _(u"Kyrgyz"),
|
||||
"lo": _(u"Laothian"),
|
||||
"lv": _(u"Latvian"),
|
||||
"lt": _(u"Lithuanian"),
|
||||
"mk": _(u"Macedonian"),
|
||||
"ms": _(u"Malay"),
|
||||
"ml": _(u"Malayalam"),
|
||||
"mt": _(u"Maltese"),
|
||||
"mr": _(u"Marathi"),
|
||||
"mn": _(u"Mongolian"),
|
||||
"ne": _(u"Nepali"),
|
||||
"no": _(u"Norwegian"),
|
||||
"or": _(u"Oriya"),
|
||||
"ps": _(u"Pashto"),
|
||||
"fa": _(u"Persian"),
|
||||
"pl": _(u"Polish"),
|
||||
"pt": _(u"Portuguese"),
|
||||
"pa": _(u"Punjabi"),
|
||||
"ro": _(u"Romanian"),
|
||||
"ru": _(u"Russian"),
|
||||
"sa": _(u"Sanskrit"),
|
||||
"sr": _(u"Serbian"),
|
||||
"sd": _(u"Sindhi"),
|
||||
"si": _(u"Sinhalese"),
|
||||
"sk": _(u"Slovak"),
|
||||
"sl": _(u"Slovenian"),
|
||||
"es": _(u"Spanish"),
|
||||
"sw": _(u"Swahili"),
|
||||
"sv": _(u"Swedish"),
|
||||
"tg": _(u"Tajik"),
|
||||
"ta": _(u"Tamil"),
|
||||
"tl": _(u"Tagalog"),
|
||||
"te": _(u"Telugu"),
|
||||
"th": _(u"Thai"),
|
||||
"bo": _(u"Tibetan"),
|
||||
"tr": _(u"Turkish"),
|
||||
"uk": _(u"Ukrainian"),
|
||||
"ur": _(u"Urdu"),
|
||||
"uz": _(u"Uzbek"),
|
||||
"ug": _(u"Uighur"),
|
||||
"vi": _(u"Vietnamese"),
|
||||
"cy": _(u"Welsh"),
|
||||
"yi": _(u"Yiddish")
|
||||
}
|
||||
|
||||
def available_languages():
|
||||
global supported_langs, d
|
||||
if supported_langs == None and d == None:
|
||||
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7")
|
||||
supported_langs = t.langs
|
||||
d = []
|
||||
for i in supported_langs:
|
||||
d.append(languages[i])
|
||||
return sorted(zip(supported_langs, d))
|
||||
return dict(sorted(languages.items(), key=lambda x: x[1]))
|
||||
|
@ -16,29 +16,30 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
############################################################
|
||||
from __future__ import unicode_literals
|
||||
import wx
|
||||
from . import translator
|
||||
import wx
|
||||
from widgetUtils import BaseDialog
|
||||
|
||||
class translateDialog(wx.Dialog):
|
||||
def __init__(self):
|
||||
super(translateDialog, self).__init__(None, -1, title=_("Translate message"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
staticDest = wx.StaticText(panel, -1, _("Target language"))
|
||||
self.dest_lang = wx.ComboBox(panel, -1, choices=[x[1] for x in translator.available_languages()], style = wx.CB_READONLY)
|
||||
self.dest_lang.SetFocus()
|
||||
self.dest_lang.SetSelection(0)
|
||||
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
listSizer.Add(staticDest)
|
||||
listSizer.Add(self.dest_lang)
|
||||
ok = wx.Button(panel, wx.ID_OK)
|
||||
ok.SetDefault()
|
||||
cancel = wx.Button(panel, wx.ID_CANCEL)
|
||||
self.SetEscapeId(wx.ID_CANCEL)
|
||||
class translateDialog(BaseDialog):
|
||||
def __init__(self):
|
||||
languages = []
|
||||
language_dict = translator.available_languages()
|
||||
for k in language_dict:
|
||||
languages.append(language_dict[k])
|
||||
super(translateDialog, self).__init__(None, -1, title=_(u"Translate message"))
|
||||
panel = wx.Panel(self)
|
||||
sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
staticDest = wx.StaticText(panel, -1, _(u"Target language"))
|
||||
self.dest_lang = wx.ComboBox(panel, -1, choices=languages, style = wx.CB_READONLY)
|
||||
self.dest_lang.SetFocus()
|
||||
self.dest_lang.SetSelection(0)
|
||||
listSizer = wx.BoxSizer(wx.HORIZONTAL)
|
||||
listSizer.Add(staticDest)
|
||||
listSizer.Add(self.dest_lang)
|
||||
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):
|
||||
return getattr(self, control).GetSelection()
|
||||
|
||||
def get_response(self):
|
||||
return self.ShowModal()
|
||||
def get(self, control):
|
||||
return getattr(self, control).GetSelection()
|
@ -1,5 +1,4 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import widgetUtils
|
||||
from wxUI.dialogs import selector
|
||||
from pubsub import pub
|
||||
@ -59,8 +58,11 @@ class createPostInteractor(base.baseInteractor):
|
||||
dlg = translator.gui.translateDialog()
|
||||
if dlg.get_response() == widgetUtils.OK:
|
||||
text_to_translate = self.view.get_text()
|
||||
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")]
|
||||
self.presenter.translate(text_to_translate, dest)
|
||||
language_dict = translator.translator.available_languages()
|
||||
for k in language_dict:
|
||||
if language_dict[k] == dlg.dest_lang.GetStringSelection():
|
||||
dst = k
|
||||
self.presenter.translate(text_to_translate, dst)
|
||||
dlg.Destroy()
|
||||
|
||||
def on_spellcheck(self, event=None):
|
||||
|
Loading…
Reference in New Issue
Block a user