Answer the question
In order to leave comments, you need to log in
How to remove special characters from a string in a request to the Google Translate API?
There is a script - it sends the selection to Google, the answer is displayed via notify-send and / or ... (it doesn’t matter)
it doesn’t work with multi-line text when I select it in the terminal, it translates only one line, I
tried adding such commands to the pipeline - it doesn’t help. CHADNT?
tr '\n' ' ' | tr '\r' ' ' | tr '\t' ' ' | tr '\v' ' '
sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g'
#!/bin/bash
TRANS="$(wget -U "Mozilla/5.0" -qO - "http://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=ru&dt=t&q=$(xsel -o | sed "s/[\"'<>]//g" | tr '\n' ' ' | tr '\r' ' ' | tr '\t' ' ' | tr '\v' ' ' | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/ /g' | sed "s/,,,0]],,.*//g" )" | awk -F'"' '{print $2}')"
if [ "$?" -eq 0 ]; then
xcowsay -t 0 "$TRANS"
#notify-send "Перевод" "$TRANS"
#echo "$TRANS" >> translate.txt
fi
Answer the question
In order to leave comments, you need to log in
it can be simpler using the data-urlencode key in curl:
$ Q='Hello world.
\`quote> Hi'
$ echo $Q
Hello world.
Hi
$ curl -s -H "user-agent: Mozilla/5.0" --get "https://translate.googleapis.com/translate_a/single?client=gtx&dt=t&sl=en&tl=ru" --data-urlencode "q=$Q"
[,null,"en"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question