6

How to add online dictionaries feature (mainly google translator) for GoldenDict

Right now a discussed solution is in html with an iframe. Is there a simple translation script/app that read a sting variable in and return it translated ?

intika
  • 1,303
  • 1
  • 10
  • 28

1 Answers1

6

Translate-shell

Translate-shell use different online translation services... we could integrate the whole application or some of it's source to provide translation to goldendict.

https://github.com/soimort/translate-shell

Quick Solution Using Translate-Shell

GoldenDict have a Programs feature in the dictionary settings section so an easy way to add an online translation feature would be to use one of those two command line tools translate-shell or the python script doodle-translate

As an example of French/English translation with google under Program section we would just add

trans -e google -s en -t fr -show-original y -show-original-phonetics n -show-translation y -no-ansi -show-translation-phonetics n -show-prompt-message n -show-languages y -show-original-dictionary n -show-dictionary n -show-alternatives n "%GDWORD%"

and

trans -e google -s fr -t en -show-original y -show-original-phonetics n -show-translation y -no-ansi -show-translation-phonetics n -show-prompt-message n -show-languages y -show-original-dictionary n -show-dictionary n -show-alternatives n "%GDWORD%"

Microsoft Windows Alternative

For windows the same solution could be used but with python + translate or may be cygwin + translate-shell

Here is a capture

enter image description here

enter image description here

intika
  • 1,303
  • 1
  • 10
  • 28
  • Can we make it work on Windows ? – ITFan May 23 '19 at 07:38
  • @ITFan i updated the answer, for windows the same solution could be used but with [python](https://www.python.org/downloads/windows/) + [translate](https://pypi.org/project/translate/) or may be [cygwin](https://www.google.com/search?hl=en&q=cygwin) + [translate-shell](https://github.com/soimort/translate-shell) – intika May 23 '19 at 07:49
  • @ intika https://pypi.org/project/translate/ uses Microsoft Translation API not Google translate. I've compared the results and found it's slower and worse comparing to Google translate. – ITFan May 23 '19 at 13:42
  • then may be the cygwin solution (i did not test it tho) or http://gnuwin32.sourceforge.net/ – intika May 23 '19 at 13:51
  • I followed this thread https://softwarerecs.stackexchange.com/questions/11919/command-line-japanese-english-machine-translation but then got these errors when run "sh trans" in cmd.exe /usr/bin/trans: trans: line 5630: syntax error near unexpected token `(' /usr/bin/trans: trans: line 5630: `gawk -f <(echo -E "$TRANS_PROGRAM") - "$@"' Do you have any idea ? – ITFan May 23 '19 at 14:12
  • you may want to try WSL or MSYS2 https://github.com/soimort/translate-shell#system-requirements and if it does not work open an issue on the projet page on github... also not sure if its related but have a look at https://github.com/soimort/translate-shell/issues/146 – intika May 23 '19 at 15:15
  • WSL works. But how could I use it as an external program with Goldendict since Translate-Shell in WSL need to be called with Bash instead of CMD.exe ? – ITFan May 23 '19 at 17:23
  • i believe you can do that with cmd `bash -c ""` check out the documentation https://docs.microsoft.com/en-us/windows/wsl/reference – intika May 23 '19 at 18:42
  • Yeah, bash trans worked ! (without -c) Thanks very much ! – ITFan May 24 '19 at 03:35
  • How can we pass the entire string? GDWORD seems to only pass the first word of the text passed. With google translate we have the option to translate sentences. – RichieHH Feb 24 '20 at 07:59
  • 1
    `"%GDWORD%"` you probably forget the quotes this should work with the whole text @RichieHH – intika Feb 24 '20 at 08:01
  • Yup, I spotted that this morning! Silly me. Thanks anyway. – RichieHH Feb 24 '20 at 14:35