Code Monkey home page Code Monkey logo

google-translate-for-goldendict's Introduction

google-translate-for-goldendict

Add Google translate for GoldenDict

GoldenDict 是一个非常好用的词典工具, 却不能整句或整段的翻译, 时常需要借助 Google translate 对于将 Google 翻译加到 GoldenDict 是一个很好的方法 φ(゜▽゜*)♪

screenshot

使用方法:

需要 python 3.7+:

pip3 install google-translate-for-goldendict

GoldenDict - 编辑 - 字典 - 字典来源 - 程式

类型: Html

名称: Google Translate

命令行: python -m googletranslate zh-CN %GDWORD%

图示: H:\PathTo\google_translate.png

类型可以设为 Html纯文本.

其中: Html 对应 -r "html". 纯文本 对应 -r "plain"

positional arguments:
  target          target language (eg: zh-CN)
  query           query string

optional arguments:
  -h, --help      show this help message and exit
  -p PROXY        proxy server (eg: 127.0.0.1:1080)
  -a ALTERNATIVE  alternative language (default: en)
  -r TYPE         result type (default: html)
  -k TKK          tkk
  -m              show synonyms
  -d              show definitions
  -e              show examples

google-translate-for-goldendict's People

Contributors

xinebf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-translate-for-goldendict's Issues

程序错误

image
根据您的说明改正后程序运行报错~

mac中无法运行

提示出现这个:/资源库/开发人员/Command Linetoo/s/usr/bin/python:没有名为googletranslate的模块

按照操作设置安装在mac中,mac默认是python2,我改命令为python3还是不行

Why now I have to use -p to add a proxy? Is this due to Google ? 为什么现在需要代理才能用 是谷歌的原因吗

Although there is a similar issue, but I think it is better to demonstrate my issue which might be a little bit different.
虽然有个差不多的问题 但是我还是说一下我的问题 可能不太一样

recently, the command can not work
最近 这个命令不能用了 前几天还能用

python3 -m googletranslate zh-CN word

there are the errors
错误长这样

Errrrrrrrrror: HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk=547524.975478&q=test (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fd47b9ea2f0>, 'Connection to translate.googleapis.com timed out. (connect timeout=5)'))

And adding -p proxy could solve a part of the issue
加代理就行了

python3 -m googletranslate -p 127.0.0.1:8118 zh-CN word

But comparing to before, it is a littile slow and sometimes it has the proxy error, like this
但是貌似比之前慢一些 有时侯也会报代理错误 然后翻译不了

(╯‵□′)╯︵┻━┻: ProxyError...

So, what is the problem. Is it because of google or this python module?
所以 是这个模块的问题 还是 google 的问题

line 39 syntax error

url = f'https://{self.http_host}/translate_a/single?client=webapp&sl=auto&tl={tl}&hl=en&dt=at&dt=bd&dt=ex&'
f'dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk={tk}&q={qry}'
报这句语法错误。

how to just keep translated text

Excuse me, how to delete ^_^: Translate en To zh-CN, 0_0: Translations of bird and so on in the .py file. Even I don’t want to keep the original text. I just want to see translated text Simply. thanks~

希望可以增加发音功能

在使用网页版谷歌翻译时,可以获取该单词的发音。是否可以在该软件上增加获取发音功能

请求过多报错

以前能用现在提示
Errrrrrrrrror: HTTPSConnectionPool(host='translate.google.com', port=443): Max retries exceeded with url: /translate_a/single?client=webapp&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk=523228.82798&q=Konstantin (Caused by ConnectTimeoutError(, 'Connection to translate.google.com timed out. (connect timeout=5)'))

在session = requests.session()后面加过 session.keep_alive = False requests.adapters.DEFAULT_RETRIES = 5 无效果,url之类的语句没摸清,无从下手,特地来这里问问老哥们,何解 ?

大佬能否提供一个更好看的样式?

如果可以,建议查询结果中^_^: Translate en To zh-CN 内容与下面的原文、原文与下面的译文 之间添加空行,使显示内容更易于分辨。建议减淡原文颜色、缩小字体,以突出显示译文。

翻译内容与网页版不一致

goldendict内是这样的
image
而在网页上是这样的
image
翻译出来的内容总是非常奇怪,似乎是因为在将翻译提交给谷歌的时候添加了不必要的换行符导致的

On entries with machine translation and dictionary translation, only machine translation is displayed

Hey. So. If you look up individual words or phrases in Google Translate, it not only provides its own machine translation. It also has built in dictionaries, which occasionally feature several translations for the same word/phrase, which are sometimes outright different from (and more accurate than) the machine translation.
A couple of examples:
gt-window

gt-pilot

(For instance, in the second example, the machine translation is a literal translation of the words "pilot" and "light", but the dictionary translations are actual translations of the entire phrase.)

Is there a way to get GT for Goldendict to display the dictionary translation as well?

Error: "target_language = sys.argv[1]"; IndexError: list index out of range.

Information

python version

python 3.8

System version

Ubuntu 18.04.3 LTS

What went wrong

Hi, thanks for your work! When I finished setting as your description, the GoldenDict thrown a error.

Reproducing the bug

Traceback (most recent call last):
File "googletranslate.py", line 125, in
target_language = sys.argv[1]
IndexError: list index out of range
Error in sys.excepthook:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
File "/usr/lib/python3/dist-packages/apport/init.py", line 5, in
from apport.report import Report
File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in
import apport.fileutils
File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in
from apport.packaging_impl import impl as packaging
File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in
import apt
File "/usr/lib/python3/dist-packages/apt/init.py", line 23, in
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
File "googletranslate.py", line 125, in
target_language = sys.argv[1]
IndexError: list index out of range

Timeout?

╰(‵□′)╯: ReadTimeout...

Query error

你好,

image

错误如图显示。
不知道哪里出了问题,是否可以给个解答?
谢谢!

'asyncio' has no attribute 'run'

Query error: The program has returned exit code 1. Traceback (most recent call last): File "C:\googletranslate.py", line 132, in <module> asyncio.run(get_translation()) AttributeError: module 'asyncio' has no attribute 'run'

Also, can you tell me how to separate the original line to the translate with a double space? I tried looking into the script and couldn't find it, I think it's much more comprehensible to have them separated with a blank line inbetween than just a /r/n.

在python中可以用,但是在goldendict中报错

报错信息:
Errrrrrrrrror: HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk=772786.881152&q=volumes%29 (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available."))

macOS下无法正常运行

系统环境macOS 10.15.3,已安装python 3及requests
按照教程在GoldenDict中配置命令行为“python /路径/googletranslate.py zh-CN %GDWORD%”后提示语法错误,考虑到macOS自带python 2,将python改为python3 不提示语法错误,提示查询错误,错误代码1,requests模块未安装

Translation results are different from Google Translate via web browser

The Translation results are different with those on Google Translate website.

I also configured "Translate Shell" on GoldenDict and the translations are different. Theoretically they should be the same since they come from Google, but something is happening.

Translations using "Translate Shell" are the same as on Google Translate via a web browser.

Translations provided by " google-translate-for-goldendict" are of lower quality. The definitions, synonyms, etc. work perfectly. The only problem is the poor quality of translation and that they do not match those provided by Google:

grafik

grafik

grafik

_----------
Instructions to install "Translate Shell" on GoldenDict are here:
https://superuser.com/questions/1319632/how-to-add-online-dictionaries-like-google-translate-to-goldendict

I hope the issue could be solved ! Thanks for your great work !

"Translate Shell" has a very ugly and disfunctional display of results. Your script is much better because the results are displayed beautifully ! The only problem currently is that translation's quality is low. Was the service provider changed ?

查询报错

查询错误:程序返回,退出代码为 1. Traceback (most recent call last): File "D:\GoldenDict\googlet\googletranslate\googletranslate.py", line 20, in from .googletranslatetk import Token ImportError: attempted relative import with no known parent package

[讨论解决方案] GoldenDict 吞空行导致翻译多段文本时排版拥挤

#6 #9

将多段文本复制到 GoldenDict 后,空行会被替换为空格以保证只有 1 行。这导致翻译时的源文本就是只有 1 行的。

如何解决这点?

我本来想到检测空格来换行,但这个似乎副作用很大。或者去修改 GoldenDict 的源码,让它把换行保留为 \n 之类的格式。

大家有没有什么更好的办法?

python调用问题

最近瞎安装command line tools, 发现翻译程式调用的不是系统python, 而是xcode下的。我删除了command line tool, 但是goldendict报错
image
尽管直接在iterm2中
image
这种问题请问老哥怎么办?
谢谢。

吞掉原文的回车,以及划词翻译的最后一个标点

Hi!
首先感谢作者的辛勤付出以及无私分享。我尝试过很多方法在GoldenDict中使用Google translate,包括添加网络词典,但只有这一个程序是奏效的。

我在使用过程中发现选取长句翻译时,发现有以下问题。(附图)

  1. 程序会吞掉句子(包括原文以及翻译结果)中的回车。在主窗口中会只保留一个回车,而在Ctrl+C+D划词翻译窗口会吞掉所有回车。
  2. 另外,划词翻译会吞掉最后一个标点。而在主窗口中则不会发生这种情况。

而我不知这是GD本身的bug还是这个小程序的原因,希望您可以留意这个小问题。:)
2019-02-20_15-12-54

好像不支持python 3.10?

使用python3.10调用报错
使用pip安装的。manjaro linux系统。之前一直用的好好的,某次系统更新之后就出问题了。
Traceback (most recent call last): File "/usr/lib/python3.10/runpy.py", line 187, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/lib/python3.10/runpy.py", line 146, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/lib/python3.10/runpy.py", line 110, in _get_module_details __import__(pkg_name) File "~/.local/lib/python3.10/site-packages/googletranslate/__init__.py", line 17, in <module> translator = Translator(map(lambda x: x.strip(), list(f))) File "~/.local/lib/python3.10/site-packages/googletranslate/client.py", line 39, in __init__ self.token_acquirer = TokenAcquirer(session=self.session, host=service_urls[0]) TypeError: 'map' object is not subscriptable

A small question about your source code

Hi xinebf,
It is very grateful for your code.
But I have a small question about the line 84 code "if resp[2] == target_language", I think the sign of equality should be the sign of inequality.

Errrrrrrrrror: Expecting value: line 1 column 1 (char 0)

配置代理后一段时间能用,但之后继续采用代理出现了这种错误

Errrrrrrrrror: Expecting value: line 1 column 1 (char 0)

取消代理则是

Errrrrrrrrror: HTTPSConnectionPool(host='translate.googleapis.com', port=443): Max retries exceeded with url: /translate_a/single?client=gtx&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk=547524.975478&q=test (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x7fd47b9ea2f0>, 'Connection to translate.googleapis.com timed out. (connect timeout=5)'))

所以是请问代理的问题还是google的问题,有没有什么办法能够解决

resultat espacé

Hi, thank for this contrib to goldendict.

Your contrib is really cool, but to get more efficient your code should update/include some cosmetics elements like:

  1. print ligne/space between blocks in the results (translate/synonym).
    the overall result is too much condense to identify quickly the block in the target language. The result should have to respect the structure of the original sentence: if there was newlines '\n' and/or carriage returns '\r', they should have print. cf. MY-Exemple below.

  2. you should insert the original sentence to translate under the translate's result one (most of people remember the composition of the sentence to translate). cf. MY-Exemple below.
    Maybe the header have to be change....

My-Exemple:

NOW:

^_^: Translate en To fr-FR
    url = get_url(alternative_language, parse_query)
    resp_en = session.get(url, timeout=3).json()
    result = get_result(result, resp_en
url = get_url (alternative_language, parse_query)
resp_en = session.get (url, délai d'attente = 3) .json ()
resultat = get_result (result, resp_en

AFTER:

^_^: Translation

to fr-FR:
url = get_url (alternative_language, parse_query)
resp_en = session.get (url, délai d'attente = 3) .json ()
resultat = get_result (result, resp_en

from en:
url = get_url(alternative_language, parse_query)
resp_en = session.get(url, timeout=3).json()
result = get_result(result, resp_en

Regards

Translation doesn't appear

Hi!
I can't seem to get this to work, either in Goldendict or just from the command line.
I have Python 3.7 installed, and have installed requests.
In Goldendict, I get the following error:
Query error: The program has returned exit code 1. Traceback (most recent call last): File "D:\gt\googletranslate.py", line 43, in gtrans() File "D:\gt\googletranslate.py", line 37, in gtrans print(result.encode('gbk', 'ignore').decode('gbk')) File "D:\Python\Python37-32\lib\encodings\cp1255.py", line 19, in encode return codecs.charmap_encode(input,self.errors,encoding_table)[0] UnicodeEncodeError: 'charmap' codec can't encode characters in position 33-34: character maps to

速度问题

谢谢码主,功能完全没问题,就是速度太慢了,能不能想想办法改进一下,如果速度也很快的话就完美了😁

The program has returned exit code 255. on Mac

Hi,
Thanks for the beautiful work.
However, it does not work on my Mac.
I have python3 installed and set "python3 /Users/myname/Data/Dicts/google-translate-for-goldendict-master/googletranslate.py zh-CN %GDWORD%" in the GoldenDict.
The error occurred with Query error: The program has returned exit code 255.

I am asking because I noticed that you have set #!/usr/bin/env python3 in the script, which should lead to the python3 as the interpreter to run the code.

Thanks in advance.

SSLError

Errrrrrrrrror: HTTPSConnectionPool(host='translate.google.cn', port=443): Max retries exceeded with url: /translate_a/single?client=webapp&sl=auto&tl=zh-CN&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=sos&dt=ss&dt=t&ssel=0&tsel=0&kc=1&tk=818253.705791&q=%25GDWORD%25 (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1123)')))

帮忙看看如何解决,公司网络,需要SSL认证

Change API to translate.google.cn

Due the reason we all know, you may want to change your api server to translate.google.cn instead of translate.googleapis.com.

Although I've already built a reverse proxy myself. XD

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.