EasyOS desktop text translation

Moderator: BarryK

Post Reply
kris777
Posts: 40
Joined: Fri Dec 25, 2020 7:53 pm
Has thanked: 3 times
Been thanked: 8 times

EasyOS desktop text translation

Post 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

Attachments
xsel.tar
(30 KiB) Downloaded 25 times
User avatar
MochiMoppel
Posts: 1294
Joined: Mon Jun 15, 2020 6:25 am
Location: Japan
Has thanked: 22 times
Been thanked: 480 times

Re: EasyOS desktop text translation

Post 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.

kris777
Posts: 40
Joined: Fri Dec 25, 2020 7:53 pm
Has thanked: 3 times
Been thanked: 8 times

Re: EasyOS desktop text translation

Post 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
User avatar
BarryK
Posts: 2875
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 149 times
Been thanked: 788 times

Re: EasyOS desktop text translation

Post 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.

kris777
Posts: 40
Joined: Fri Dec 25, 2020 7:53 pm
Has thanked: 3 times
Been thanked: 8 times

Re: EasyOS desktop text translation

Post 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:

Post Reply

Return to “EasyOS”