Hello. On the Internet, a script has been walking for quite some time, allowing you to translate selected text in any application. The algorithm is simple - by calling the script, we read the contents of the primary selection (xsel to help), send a request to the Google translator and output the result in, for example, notify-send. How to call this script automatically when you change the primary selection?
- script - scripts, dozens of them :) I wrote three pieces myself, for Yandex too. There in the simplest case of scribbling - 3-4 lines. But there ponavorocheny. And as a matter of fact - yes, it is stupid to loop, to check the selection with some frequency and to compare with the previous one. Only now the benefits of this are very doubtful, the harm seems more ... - PinkTux
- it is worth mentioning that sending everything that you allocate to Google is not the brightest thought ... - Fat-Zer
- @ Fat-Zer, and you definitely noticed that. Paranoid something relaxed in me))) - alvoro
|
1 answer
On the example of Yandex:
#!/bin/bash key="ваш ключ" old="$(xsel -o)" new="" while true; do new="$(xsel -o)" if [ "$old" != "$new" ]; then old="$new" translated="$(wget -qO - "https://translate.yandex.net/api/v1.5/tr.json/translate?key=$key&text=$new&lang=ru")" notify-send -u critical "$new" "$(echo $translated | sed 's/.*\[\"\(.*\)\"\].*/\1/')" fi sleep 1 done sleepat leastiftake out ... - Fat-Zer- Yes it is. As noted in the comments to the question, you should not use this script on an ongoing basis. But, for example, when reading a long text in an incomprehensible language, it is very suitable - alvoro
- @ Fat-Zer, exactly, he sketched on his knee, was wrong :) - PinkTux
|