Changed translation service to google Translate

This commit is contained in:
Manuel Cortez 2021-02-24 11:41:45 -06:00
parent b8ef10af3f
commit 273f25c24f
6 changed files with 139 additions and 135 deletions

View File

@ -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. * 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. * 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 ### 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. * 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. * 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 ## News in Version 0.24

View File

@ -9,7 +9,6 @@ requests-oauthlib
future future
arrow arrow
backports.functools_lru_cache backports.functools_lru_cache
yandex.translate
googletrans googletrans
mutagen mutagen
mock mock

View File

@ -1,6 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import platform import platform
from . import translator
if platform.system() == "Windows": if platform.system() == "Windows":
from . import wx_ui as gui from . import wx_ui as gui
from . import translator

View File

@ -1,115 +1,116 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals import logging
from builtins import zip from googletrans import Translator, LANGUAGES
from yandex_translate import YandexTranslate
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"): def translate(text="", target="en"):
t = YandexTranslate("trnsl.1.1.20161012T134532Z.d01b9c75fc39aa74.7d1be75a5166a80583eeb020e10f584168da6bf7") global t
vars = dict(text=text, lang=target) log.debug("Received translation request for language %s, text=%s" % (target, text))
return t.translate(**vars)["text"][0] if t == None:
t = Translator()
vars = dict(text=text, dest=target)
return t.translate(**vars).text
supported_langs = None supported_langs = None
d = None
languages = { languages = {
"af": _("Afrikaans"), "af": _(u"Afrikaans"),
"sq": _("Albanian"), "sq": _(u"Albanian"),
"am": _("Amharic"), "am": _(u"Amharic"),
"ar": _("Arabic"), "ar": _(u"Arabic"),
"hy": _("Armenian"), "hy": _(u"Armenian"),
"az": _("Azerbaijani"), "az": _(u"Azerbaijani"),
"eu": _("Basque"), "eu": _(u"Basque"),
"be": _("Belarusian"), "be": _(u"Belarusian"),
"bn": _("Bengali"), "bn": _(u"Bengali"),
"bh": _("Bihari"), "bh": _(u"Bihari"),
"bg": _("Bulgarian"), "bg": _(u"Bulgarian"),
"my": _("Burmese"), "my": _(u"Burmese"),
"ca": _("Catalan"), "ca": _(u"Catalan"),
"chr": _("Cherokee"), "chr": _(u"Cherokee"),
"zh": _("Chinese"), "zh": _(u"Chinese"),
"zh-CN": _("Chinese_simplified"), "zh-CN": _(u"Chinese_simplified"),
"zh-TW": _("Chinese_traditional"), "zh-TW": _(u"Chinese_traditional"),
"hr": _("Croatian"), "hr": _(u"Croatian"),
"cs": _("Czech"), "cs": _(u"Czech"),
"da": _("Danish"), "da": _(u"Danish"),
"dv": _("Dhivehi"), "dv": _(u"Dhivehi"),
"nl": _("Dutch"), "nl": _(u"Dutch"),
"en": _("English"), "en": _(u"English"),
"eo": _("Esperanto"), "eo": _(u"Esperanto"),
"et": _("Estonian"), "et": _(u"Estonian"),
"tl": _("Filipino"), "tl": _(u"Filipino"),
"fi": _("Finnish"), "fi": _(u"Finnish"),
"fr": _("French"), "fr": _(u"French"),
"gl": _("Galician"), "gl": _(u"Galician"),
"ka": _("Georgian"), "ka": _(u"Georgian"),
"de": _("German"), "de": _(u"German"),
"el": _("Greek"), "el": _(u"Greek"),
"gn": _("Guarani"), "gn": _(u"Guarani"),
"gu": _("Gujarati"), "gu": _(u"Gujarati"),
"iw": _("Hebrew"), "iw": _(u"Hebrew"),
"hi": _("Hindi"), "hi": _(u"Hindi"),
"hu": _("Hungarian"), "hu": _(u"Hungarian"),
"is": _("Icelandic"), "is": _(u"Icelandic"),
"id": _("Indonesian"), "id": _(u"Indonesian"),
"iu": _("Inuktitut"), "iu": _(u"Inuktitut"),
"ga": _("Irish"), "ga": _(u"Irish"),
"it": _("Italian"), "it": _(u"Italian"),
"ja": _("Japanese"), "ja": _(u"Japanese"),
"kn": _("Kannada"), "kn": _(u"Kannada"),
"kk": _("Kazakh"), "kk": _(u"Kazakh"),
"km": _("Khmer"), "km": _(u"Khmer"),
"ko": _("Korean"), "ko": _(u"Korean"),
"ku": _("Kurdish"), "ku": _(u"Kurdish"),
"ky": _("Kyrgyz"), "ky": _(u"Kyrgyz"),
"lo": _("Laothian"), "lo": _(u"Laothian"),
"lv": _("Latvian"), "lv": _(u"Latvian"),
"lt": _("Lithuanian"), "lt": _(u"Lithuanian"),
"mk": _("Macedonian"), "mk": _(u"Macedonian"),
"ms": _("Malay"), "ms": _(u"Malay"),
"ml": _("Malayalam"), "ml": _(u"Malayalam"),
"mt": _("Maltese"), "mt": _(u"Maltese"),
"mr": _("Marathi"), "mr": _(u"Marathi"),
"mn": _("Mongolian"), "mn": _(u"Mongolian"),
"ne": _("Nepali"), "ne": _(u"Nepali"),
"no": _("Norwegian"), "no": _(u"Norwegian"),
"or": _("Oriya"), "or": _(u"Oriya"),
"ps": _("Pashto"), "ps": _(u"Pashto"),
"fa": _("Persian"), "fa": _(u"Persian"),
"pl": _("Polish"), "pl": _(u"Polish"),
"pt": _("Portuguese"), "pt": _(u"Portuguese"),
"pa": _("Punjabi"), "pa": _(u"Punjabi"),
"ro": _("Romanian"), "ro": _(u"Romanian"),
"ru": _("Russian"), "ru": _(u"Russian"),
"sa": _("Sanskrit"), "sa": _(u"Sanskrit"),
"sr": _("Serbian"), "sr": _(u"Serbian"),
"sd": _("Sindhi"), "sd": _(u"Sindhi"),
"si": _("Sinhalese"), "si": _(u"Sinhalese"),
"sk": _("Slovak"), "sk": _(u"Slovak"),
"sl": _("Slovenian"), "sl": _(u"Slovenian"),
"es": _("Spanish"), "es": _(u"Spanish"),
"sw": _("Swahili"), "sw": _(u"Swahili"),
"sv": _("Swedish"), "sv": _(u"Swedish"),
"tg": _("Tajik"), "tg": _(u"Tajik"),
"ta": _("Tamil"), "ta": _(u"Tamil"),
"tl": _("Tagalog"), "tl": _(u"Tagalog"),
"te": _("Telugu"), "te": _(u"Telugu"),
"th": _("Thai"), "th": _(u"Thai"),
"bo": _("Tibetan"), "bo": _(u"Tibetan"),
"tr": _("Turkish"), "tr": _(u"Turkish"),
"uk": _("Ukrainian"), "uk": _(u"Ukrainian"),
"ur": _("Urdu"), "ur": _(u"Urdu"),
"uz": _("Uzbek"), "uz": _(u"Uzbek"),
"ug": _("Uighur"), "ug": _(u"Uighur"),
"vi": _("Vietnamese"), "vi": _(u"Vietnamese"),
"cy": _("Welsh"), "cy": _(u"Welsh"),
"yi": _("Yiddish") "yi": _(u"Yiddish")
} }
def available_languages(): def available_languages():
global supported_langs, d return dict(sorted(languages.items(), key=lambda x: x[1]))
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))

View File

@ -16,17 +16,21 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################ ############################################################
from __future__ import unicode_literals
import wx
from . import translator from . import translator
import wx
from widgetUtils import BaseDialog
class translateDialog(wx.Dialog): class translateDialog(BaseDialog):
def __init__(self): def __init__(self):
super(translateDialog, self).__init__(None, -1, title=_("Translate message")) 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) panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.VERTICAL) sizer = wx.BoxSizer(wx.VERTICAL)
staticDest = wx.StaticText(panel, -1, _("Target language")) staticDest = wx.StaticText(panel, -1, _(u"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 = wx.ComboBox(panel, -1, choices=languages, style = wx.CB_READONLY)
self.dest_lang.SetFocus() self.dest_lang.SetFocus()
self.dest_lang.SetSelection(0) self.dest_lang.SetSelection(0)
listSizer = wx.BoxSizer(wx.HORIZONTAL) listSizer = wx.BoxSizer(wx.HORIZONTAL)
@ -39,6 +43,3 @@ class translateDialog(wx.Dialog):
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()

View File

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals
import widgetUtils import widgetUtils
from wxUI.dialogs import selector from wxUI.dialogs import selector
from pubsub import pub from pubsub import pub
@ -59,8 +58,11 @@ class createPostInteractor(base.baseInteractor):
dlg = translator.gui.translateDialog() dlg = translator.gui.translateDialog()
if dlg.get_response() == widgetUtils.OK: if dlg.get_response() == widgetUtils.OK:
text_to_translate = self.view.get_text() text_to_translate = self.view.get_text()
dest = [x[0] for x in translator.translator.available_languages()][dlg.get("dest_lang")] language_dict = translator.translator.available_languages()
self.presenter.translate(text_to_translate, dest) for k in language_dict:
if language_dict[k] == dlg.dest_lang.GetStringSelection():
dst = k
self.presenter.translate(text_to_translate, dst)
dlg.Destroy() dlg.Destroy()
def on_spellcheck(self, event=None): def on_spellcheck(self, event=None):