浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

这个事一个shell函数,使用了有道翻译提供的翻译服务

 

Shell代码  收藏代码
  1. ts(){  
  2.   
  3. curl -s \  
  4.         "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top" \  
  5.      -d \  
  6.     "type=AUTO& i=$1&doctype=json&xmlVersion=1.4&keyfrom=fanyi.web&ue=UTF-8&typoResult=true&flag=false" \  
  7.         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;  
  8.   
  9. return 0;  
  10. }  
 

设置如下:

linux用户:

1.添加此脚本到~/.bashrc的末尾

2.source ~/.bashrc

Mac osX用户:

 

1.添加此脚本到~/.bash_profile的末尾,没有就新建

2.source ~/.bash_profile

 

使用:

 

 

Shell代码  收藏代码
  1. ts hello  
  2. 你好  
  3. ts "how are you?"  
  4. 你好吗?  
 
也可以翻译中文。

 

posted on 2012-04-03 15:15  lexus  阅读(352)  评论(0编辑  收藏  举报