Page 1 of 1

EasyOS desktop text translation

Posted: Sun Jul 02, 2023 7:44 pm
by kris777

If someone wants to use a clever translation of text using google translator, they can use several programs and a script. In EasyOS, only the xsel program needs to be installed.
Then we create a script, i.e. we create a file with the name: translate
in the path:

Code: Select all

/usr/local/bin/translate

Enter the content and give executable permissions chmod +x

Code: Select all

#!/usr/bin/env bash

xsel -o | python3 -c "import sys,urllib.request,json; r = json.loads(urllib.request.urlopen(urllib.request.Request('http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=pl&dt=t&q=' + urllib.parse.quote(sys.stdin.read().replace('\n',' ')), None, { 'User-Agent' : 'Mozilla/5.0' })).read().decode('utf-8')); [print(t[0], end='') for t in r[0]]; print('\n--==<<>>==--'); [print(t[1], end='') for t in r[0]];" | zenity --wrap --text-info --width=500 --height=500 --title="Translate"

Now we create a keyboard shortcut in the system that will run this script. In EasyOS it is: EasyJWM / Manage JWM keyboard shortcuts let it be for example Ctrl+t

Code: Select all

exec:/usr/local/bin/translate

Image
Now all you have to do is select some text in the OS: web browser / text file, etc. and click Ctrl + t on the keyboard and a window with the translated text will be displayed on the desktop.
Image
Of course, we also need to specify the language into which the text will be translated, in my case it is Polish. The change is made in the script: translate ... find the line with the text and change pl to your own language :-)

Google translate language codes https://gist.github.com/JT5D/a2fdfefa80124a06f5a9
It's a pity that there is no such easy option to translate text as standard in the system :D

Greetings


Re: EasyOS desktop text translation

Posted: Sun Jul 02, 2023 11:07 pm
by MochiMoppel
kris777 wrote: Sun Jul 02, 2023 7:44 pm

In EasyOS, only the xsel program needs to be installed.
Then we create a script, i.e. we create a file with the name: translate

Most Puppies have xclip already installed. May already be present in EasyOS. Both programs do essentially the same.


Re: EasyOS desktop text translation

Posted: Mon Jul 03, 2023 4:46 am
by kris777

Most Puppies have xclip already installed. May already be present in EasyOS. Both programs do essentially the same.

uppsss .... you don't really need to install anything :D

this entry works fine too

Code: Select all

#!/usr/bin/env bash
echo "$(xsel -o | trans -b -no-ansi -u firefox -t pl)" | yad --title="Google Translate" --width=500 --height=450 --center --text-info --wrap

Re: EasyOS desktop text translation

Posted: Mon Jul 03, 2023 6:53 am
by BarryK

The Document menu category has Gxlat, created by Vovchik.

Highlight any text, middle-click in Gxlat to paste it, click the "Translate" button.


Re: EasyOS desktop text translation

Posted: Mon Jul 03, 2023 10:08 am
by kris777

Highlight any text, middle-click in Gxlat to paste it, click the "Translate" button.

You can also use a web browser and the google translate service, copy the text, paste it and click the translator ... but we are looking for the simplest method :thumbup2: