[Ubuntu-zh] [shlug] Re: 一个翻译脚本,用于终端的命令行

依云 lilydjwg在gmail.com
星期五 五月 18 09:27:08 UTC 2012


直接写到终端就行了嘛,UTF-8 嘛。

PS: 国内的网站都是这样,明明是 XML / JSON 的数据,Content-Type 非要写成
text/html,害得我火狐显示得丑死了……

On Fri, May 18, 2012 at 02:41:13PM +0800, Hex Lee wrote:
> 返回的结果中,音标特殊字符,不知在终端下如何显示,所以就没有弄,知道的同学赶快跳出来啊。
> 发音的问题,这里也是可以实现的,返回结果中有音频文件的地址,不过需要mp3播放的支持,确实有需要的同学可以折腾折腾。
> 
> 在 2012年5月18日 上午12:09,HappyPoly Yang <happypoly.yang在gmail.com>写道:
> 
> > 不错不错,正在使用中,感谢~``:)加个音标就更完美了,如果还能够实现发音。。
> >
> > 在 2012年5月12日 下午4:16,Hex Lee <lihe757在gmail.com>写道:
> >
> > > 大家好:
> > > [image: 内嵌图片 1]
> > > 我根据chrome 插件halo word dictionary 写了一个新版本的bash脚本与大家分享,另外感谢他们提供的翻译服务
> > > 功能:
> > > 纯粹的字典功能,一次只能查一个单词
> > > 特色:
> > > 更详细,带词性,带例句
> > >
> > > 效果如下:
> > > $ ts apple
> > > n.苹果, 珍宝, 家伙
> > >
> > > My uncle has an apple orchard.
> > > 我叔叔拥有一个苹果园。
> > > The apple pie and custard are delicious.
> > > 苹果饼和软冻的味道好极了。
> > > The apple trees are blossoming.
> > > 苹果树正在开花。
> > >
> > > $ ts driver
> > > n.驾驶员, 司机, 驱动器
> > >
> > > The driver was not to blame for the accident.
> > > 这次事故怪不着司机。
> > > I'm a hopeless driver, but the examiner let me through.
> > > 我开车的技术糟透了,但考官让我及格了。
> > > The driver was weaving his way through the traffic.
> > > 司机在车辆和人流中曲折前进。
> > >
> > > bash脚本,使用方法和以前一样加入到~/.bashrc(for linux) :
> > >
> > > ts(){
> > > result=`curl -s \
> > >        "http://dict.cn/ws.php?utf8=true&q=$1" `;
> > >
> > > echo $result | sed -r -n 's/.*<def>([^<]+)<\/def>.*/\1/p';
> > >
> > > #examples
> > > echo $result \
> > >    | sed -r -n 's/.*def> (<sent><orig>.*<\/sent>).*/\1/p' \
> > >    | sed 's/<em>//g' \
> > >    | sed 's/<\/em>//g' \
> > >    | sed 's/<trans>/\n/g' \
> > >    | sed 's/<orig>/\n/g' \
> > >    | sed 's/<[^<>]*>//g';
> > >
> > > return 0;
> > >
> > > }
> > >
> > >
> > > 2012/4/13 codewalkertse <xyy.xx.victor在gmail.com>
> > >
> > > > 非常好的一个脚本 感谢分享
> > > >
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>         "http://fanyi.youdao.com/**translate?smartresult=dict&**
> > > >> smartresult=rule&smartresult=**ugc&sessionFrom=dict.top<
> > >
> > http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top
> > > >"
> > > >> \
> > > >>      -d \
> > > >> "type=AUTO&
> > > i=$1&doctype=json&xmlVersion=**1.4&keyfrom=fanyi.web&ue=UTF-*
> > > >> *8&typoResult=true&flag=false" \
> > > >>         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;
> > > >>
> > > >> return 0;
> > > >> }
> > > >>
> > > >> 设置如下:
> > > >> linux用户:
> > > >> 1.添加此脚本到~/.bashrc的末尾
> > > >> 2.source ~/.bashrc
> > > >> Mac osX用户:
> > > >>
> > > >> 1.添加此脚本到~/.bash_profile的末尾,**没有就新建
> > > >> 2.source ~/.bash_profile
> > > >>
> > > >> 使用:
> > > >>
> > > >>
> > > >> Shell代码
> > > >> $ ts hello
> > > >> 你好
> > > >> $ ts "how are you?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 <http://hexlee.iteye.com/blog/1442506>
> > > >>
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>         "http://fanyi.youdao.com/**translate?smartresult=dict&**
> > > >> smartresult=rule&smartresult=**ugc&sessionFrom=dict.top<
> > >
> > http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top
> > > >"
> > > >> \
> > > >>      -d \
> > > >> "type=AUTO&
> > > i=$1&doctype=json&xmlVersion=**1.4&keyfrom=fanyi.web&ue=UTF-*
> > > >> *8&typoResult=true&flag=false" \
> > > >>         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;
> > > >>
> > > >> return 0;
> > > >> }
> > > >>
> > > >> 设置如下:
> > > >> linux用户:
> > > >> 1.添加此脚本到~/.bashrc的末尾
> > > >> 2.source ~/.bashrc
> > > >> Mac osX用户:
> > > >>
> > > >> 1.添加此脚本到~/.bash_profile的末尾,**没有就新建
> > > >> 2.source ~/.bash_profile
> > > >>
> > > >> 使用:
> > > >>
> > > >>
> > > >> Shell代码
> > > >> $ ts hello
> > > >> 你好
> > > >> $ ts "how are you?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 <http://hexlee.iteye.com/blog/1442506>
> > > >>
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>         "http://fanyi.youdao.com/**translate?smartresult=dict&**
> > > >> smartresult=rule&smartresult=**ugc&sessionFrom=dict.top<
> > >
> > http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top
> > > >"
> > > >> \
> > > >>      -d \
> > > >> "type=AUTO&
> > > i=$1&doctype=json&xmlVersion=**1.4&keyfrom=fanyi.web&ue=UTF-*
> > > >> *8&typoResult=true&flag=false" \
> > > >>         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;
> > > >>
> > > >> return 0;
> > > >> }
> > > >>
> > > >> 设置如下:
> > > >> linux用户:
> > > >> 1.添加此脚本到~/.bashrc的末尾
> > > >> 2.source ~/.bashrc
> > > >> Mac osX用户:
> > > >>
> > > >> 1.添加此脚本到~/.bash_profile的末尾,**没有就新建
> > > >> 2.source ~/.bash_profile
> > > >>
> > > >> 使用:
> > > >>
> > > >>
> > > >> Shell代码
> > > >> $ ts hello
> > > >> 你好
> > > >> $ ts "how are you?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 <http://hexlee.iteye.com/blog/1442506>
> > > >>
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>         "http://fanyi.youdao.com/**translate?smartresult=dict&**
> > > >> smartresult=rule&smartresult=**ugc&sessionFrom=dict.top<
> > >
> > http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top
> > > >"
> > > >> \
> > > >>      -d \
> > > >> "type=AUTO&
> > > i=$1&doctype=json&xmlVersion=**1.4&keyfrom=fanyi.web&ue=UTF-*
> > > >> *8&typoResult=true&flag=false" \
> > > >>         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;
> > > >>
> > > >> return 0;
> > > >> }
> > > >>
> > > >> 设置如下:
> > > >> linux用户:
> > > >> 1.添加此脚本到~/.bashrc的末尾
> > > >> 2.source ~/.bashrc
> > > >> Mac osX用户:
> > > >>
> > > >> 1.添加此脚本到~/.bash_profile的末尾,**没有就新建
> > > >> 2.source ~/.bash_profile
> > > >>
> > > >> 使用:
> > > >>
> > > >>
> > > >> Shell代码
> > > >> $ ts hello
> > > >> 你好
> > > >> $ ts "how are you?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 <http://hexlee.iteye.com/blog/1442506>
> > > >>
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>         "http://fanyi.youdao.com/**translate?smartresult=dict&**
> > > >> smartresult=rule&smartresult=**ugc&sessionFrom=dict.top<
> > >
> > http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=dict.top
> > > >"
> > > >> \
> > > >>      -d \
> > > >> "type=AUTO&
> > > i=$1&doctype=json&xmlVersion=**1.4&keyfrom=fanyi.web&ue=UTF-*
> > > >> *8&typoResult=true&flag=false" \
> > > >>         | sed -E -n 's/.*tgt":"([^"]+)".*/\1/p' ;
> > > >>
> > > >> return 0;
> > > >> }
> > > >>
> > > >> 设置如下:
> > > >> linux用户:
> > > >> 1.添加此脚本到~/.bashrc的末尾
> > > >> 2.source ~/.bashrc
> > > >> Mac osX用户:
> > > >>
> > > >> 1.添加此脚本到~/.bash_profile的末尾,**没有就新建
> > > >> 2.source ~/.bash_profile
> > > >>
> > > >> 使用:
> > > >>
> > > >>
> > > >> Shell代码
> > > >> $ ts hello
> > > >> 你好
> > > >> $ ts "how are you?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 <http://hexlee.iteye.com/blog/1442506>
> > > >>
> > > >
> > > -------------- 下一部分 --------------
> > > 一个HTML附件被移除...
> > > URL: <
> > >
> > https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20120512/c7cff649/attachment.html
> > > >
> > > -------------- 下一部分 --------------
> > > A non-text attachment was scrubbed...
> > > Name: Screen Shot 2012-05-12 at 4.06.58 PM.png
> > > Type: image/png
> > > Size: 21389 bytes
> > > Desc: 不可用
> > > URL: <
> > >
> > https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20120512/c7cff649/attachment.png
> > > >
> > > --
> > > ubuntu-zh mailing list
> > > ubuntu-zh在lists.ubuntu.com
> > > https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh
> > >
> >
> >
> >
> > --
> >
> > zhiwei.yang(Poly)
> >
> > Signature:Creations build things.
> >
> > Wuhan,China.Best Regards.
> >
> > Thanks for reading.
> > -------------- 下一部分 --------------
> > 一个HTML附件被移除...
> > URL: <
> > https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20120518/32836116/attachment.html
> > >
> > --
> > ubuntu-zh mailing list
> > ubuntu-zh在lists.ubuntu.com
> > https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh
> >
> -------------- 下一部分 --------------
> 一个HTML附件被移除...
> URL: <https://lists.ubuntu.com/archives/ubuntu-zh/attachments/20120518/4ee8de66/attachment.html>
> -- 
> ubuntu-zh mailing list
> ubuntu-zh在lists.ubuntu.com
> https://lists.ubuntu.com/mailman/listinfo/ubuntu-zh

-- 
Best regards,
lilydjwg

Linux Vim Python 我的博客:
http://lilydjwg.is-programmer.com/
-- 
A: Because it obfuscates the reading.
Q: Why is top posting so bad?



关于邮件列表 ubuntu-zh 的更多信息