everybody. I want to write a bash-script to use the google translate from the terminal and translate the English into Chinese. My plan is first use the wget to translate the English,then use sed to get the result. So i use
wget -qO- --header="Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" --header="Accept-Charset:GBK,utf-8;q=0.7,*;q=0.3" --header="Accept-Encoding:gzip,deflate,sdch" --header="Accept-Language:en-US,en;q=0.8,zh-CN;q=0.6,zh;q=0.4" -U "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.27 Safari/536.11" http://translate.google.cn/#en/zh-CN/hello | gunzip > out.html.
And i also just tried
wget -U "Mozilla/5.0" http://translate.google.cn/#en/zh-CN/hello.
Both the results of them seem not what i want, because i can't find
你好 in Chinese from the result.
What's the problem with me?
curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=zh-CN&ie=UTF-8&oe=UTF-8&multires=1&prev=btn&ssel=0&tsel=0&sc=1'
The previous command will print the following result:
You can then use sed to obtain the result as follows:
curl -A "Mozilla/5.0" 'http://translate.google.com/translate_a/t?client=t&text=hello&hl=en&sl=en&tl=zh-CN&ie=UTF-8&oe=UTF-8&multires=1&prev=btn&ssel=0&tsel=0&sc=1' | sed 's/\[\[\["\([^"]*\).*/\1/'
However, as others have mentioned you should not be using this to abuse the translate service, and for anything beyond experimentation or CLI-badassery you should (and probably have to) use the Google Translate API to avoid getting yourself in trouble. Google monitors usage, and will most definitely detect any attempts to abuse their services.
P.S: I'm not qualified to give legal advice, and what I wrote above regarding what I consider to be "not abusing the service" is 100% personal opinion, so please don't take it as the final say in the matter.