Replaced translation services. Fixes #355

This commit is contained in:
Manuel Cortez 2021-01-26 16:01:26 -06:00
parent 304d91e8b7
commit 351f700927
3 changed files with 17 additions and 4 deletions

View File

@ -12,6 +12,7 @@
* TWBlue can upload images in Tweets and replies again. ([#240,](https://github.com/manuelcortez/TWBlue/issues/240))
* Fixed the way we use to count characters in Twitter. The new methods in TWBlue take into account special characters and URLS as documented in Twitter. ([#199,](https://github.com/manuelcortez/TWBlue/issues/199) [#315](https://github.com/manuelcortez/TWBlue/issues/315))
* Proxy support now works as expected.
* Changed translation service from yandex.translate to Google Translator. ([#355,](https://github.com/manuelcortez/TWBlue/issues/355))
* And more. ([#352,](https://github.com/manuelcortez/TWBlue/issues/352))
## Changes in version 0.95

View File

@ -16,7 +16,9 @@ futures
winpaths
PySocks
win_inet_pton
yandex.translate
# Install the latest RC of this lib
# see https://github.com/ssut/py-googletrans/issues/234
googletrans==4.0.0-rc1
idna<3,>=2.5
chardet
urllib3

View File

@ -1,9 +1,19 @@
# -*- coding: utf-8 -*-
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 = Translator()
vars = dict(text=text, dst=target)
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
@ -103,4 +113,4 @@ languages = {
}
def available_languages():
return languages
return dict(sorted(languages.items(), key=lambda x: x[1]))