trs () {
words=`echo $* | sed 's/ /+/g'`
sl='en' # 'auto' 自动检测但翻译比较差
tl='zh-CN'
url="http://translate.google.cn/translate_a/single"
params="client=p&sl=$sl&tl=$tl&hl=en&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&source=btn&ssel=0&tsel=0&kc=1&tk=829750.693266&q=$words"
header='User-Agent:Mozilla/4.0'
curl --silent -H $header "$url?$params" | sed -e 's/[,]\{2,\}/,/g' -e 's/\[,/\[/g' | jq '.[0]'
}
示例:
yantze@xxx $ trs simple
[
[
"简单",
"simple",
2
],
[
"Jiǎndān",
"ˈsimpəl"
]
]
dict () {
words=$*
key='1648104049'
keyfrom='aobailaile'
url="http://fanyi.youdao.com/openapi.do"
params="keyfrom=$keyfrom&key=$key&type=data&doctype=json&version=1.1"
curl --silent --data-urlencode "q=$words" "$url?$params" | jq -C '.'
}
示例:
yantze@xxx $ dict complex
{
"translation": [
"复杂的"
],
"basic": {
"us-phonetic": "kəm'plɛks; 'kɑm,plɛks",
"phonetic": "'kɒmpleks",
"uk-phonetic": "'kɒmpleks",
"explains": [
"n. 复合体;综合设施",
"adj. 复杂的;合成的"
]
}
}
trsl () {
while true ;do read words; trs $words; done
}
jq
,让系统支持格式化 json 字符串, https://stedolan.github.io/jq/.translate_functions
.bashrc
或者 .zshrc
文件末尾添加 . .translate_functions
即可为了简单可控所以成文,下面是一些功能全面的软件:
源代码: https://gist.github.com/yantze/6114ed61499f1600d0dc6e071647b190
trs 方法的 params 变量需要修改一下:
trs () {
# google api only support + concat
words=`echo $* | sed 's/ /+/g'`
sl='en' # 'auto' 自动检测但翻译比较差
tl='zh-CN'
params="client=gtx&ie=UTF-8&oe=UTF-8&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&dt=at&sl=$sl&tl=$tl&hl=en&q=$words"
url="http://translate.google.cn/translate_a/single"
header='User-Agent:Mozilla/4.0'
curl --silent -H $header "$url?$params" | sed -e 's/[,]\{2,\}/,/g' -e 's/\[,/\[/g' | jq '.[0]'
}
1
jemyzhang 2016-08-24 14:15:41 +08:00
git hub 上 antigen 安装后,trans 卡主,是不是要翻墙?
|