1
I use a bash script to translate words from other languages into Portuguese. It always worked very well, but from a few days to here became extremely slow, to the point that I could not use it.
some people informed me that the problem could be in the "wget".
I did some tests replacing "wget" with "Axel" or "aria2c" and the speed returned to normal, but using these two commands I cannot get the translation.
The original code is this one:
#!/usr/bin/env bash
text="$(xsel -o)"
translate="$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=pt&dt=t&q=$(echo $text | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
echo -e "Original text:" "$text"'\n' > /tmp/notitrans
echo "Translation:" "$translate" >> /tmp/notitrans
zenity --text-info --title="Translation" --filename=/tmp/notitrans
Line 3 of this code, replacing "wget" with "Axel" is:
translate="$(axel -n 4 "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=pt&dt=t&q=$(echo $text | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
And replacing "wget" with "aria2c" is:
translate="$(aria2c "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=pt&dt=t&q=$(echo $text | sed "s/[\"'<>]//g")" | sed "s/,,,0]],,.*//g" | awk -F'"' '{print $2}')"
Maybe I don’t know how to set the options for Axel and Aria2c. For me it doesn’t matter if any of them, I need the code to work again. Would anyone know to steer me in that direction?
There is already a tool that already does this, from a look: https://github.com/soimort/translate-shell
– gfleck
Gfleck, this tool is for terminal use only. The script I use is more free, I can use it in any environment and therefore it is more practical. As I read long books, it is faster to have a script that recognizes highlighted words and shows the definition automatically; this greatly speeds up reading.
– Ricardo