To be honest, it was a little offensive. That's what they lack!
Of course, I started looking for a way out for myself and my friends. And I found it.
This output was the translators library (Yandex can also do it).
In general, the code remains the same as in the previous article , the logic has changed slightly.
Everything related to Yandex was removed, the langdetect and translators libraries were added . The first is to define the language, because without access to the API, you would have to do it manually. The second, respectively, is the module for accessing the google translator via urllib and requests.
Here are all the innovations:
................
from langdetect import detect
import translators as ts
................
indetect = detect(clip())
def definition():
if indetect == 'ru':
langout = 'en'
else:
langout = 'ru'
return langout
def translate():
output = []
output = ts.google(clip(), to_language=definition(), if_use_cn_host=True)
return output
................
The file ~ / .local / lib / python3.8 / site-packages / translators / apis.py has also been changed
53 #logger.add(sys.stdout, format='[{time:HH:mm:ss}] <lvl>{message}</lvl>', level='INFO')
120 #sys.stderr.write(f'Using {data.get("country")} server backend.\n')
144 self.cn_host_url = 'https://translate.google.ru'
151 self.output_zh = 'ru-RU'
Well, I don't need the debug output at all, lines 53 and 120, as well as the default server and the output in 144 and 151 changed from Chinese to Russian.
Project on github .
PS: Translator from Google, as it turned out, copes with its purpose better than Yandex.