EasyOS desktop text translation
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
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.
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
Greetings