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

2012-05-18 文章 依云
直接写到终端就行了嘛,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 写道:
> 
> > 不错不错,正在使用中,感谢~``:)加个音标就更完美了,如果还能够实现发音。。
> >
> > 在 2012年5月12日 下午4:16,Hex Lee 写道:
> >
> > > 大家好:
> > > [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>.*/\1/p';
> > >
> > > #examples
> > > echo $result \
> > >| sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
> > >| sed 's///g' \
> > >| sed 's/<\/em>//g' \
> > >| sed 's//\n/g' \
> > >| sed 's//\n/g' \
> > >| sed 's/<[^<>]*>//g';
> > >
> > > return 0;
> > >
> > > }
> > >
> > >
> > > 2012/4/13 codewalkertse 
> > >
> > > > 非常好的一个脚本 感谢分享
> > > >
> > > >
> > > > 在 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?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 
> > > >>
> > > >
> > > > 在 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?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 
> > > >>
> > > >
> > > > 在 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?"
> > > >> 你好吗?
> > > >>
> > > >> 也可以翻译中文。
> > > >>
> > > >> 原文地址 
> > > >>
> > > >
> > > > 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
> > > >>
> > > >> ts(){
> > > >>
> > > >> curl -s \
> > > >>   

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

返回的结果中,音标特殊字符,不知在终端下如何显示,所以就没有弄,知道的同学赶快跳出来啊。
发音的问题,这里也是可以实现的,返回结果中有音频文件的地址,不过需要mp3播放的支持,确实有需要的同学可以折腾折腾。

在 2012年5月18日 上午12:09,HappyPoly Yang 写道:

> 不错不错,正在使用中,感谢~``:)加个音标就更完美了,如果还能够实现发音。。
>
> 在 2012年5月12日 下午4:16,Hex Lee 写道:
>
> > 大家好:
> > [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>.*/\1/p';
> >
> > #examples
> > echo $result \
> >| sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
> >| sed 's///g' \
> >| sed 's/<\/em>//g' \
> >| sed 's//\n/g' \
> >| sed 's//\n/g' \
> >| sed 's/<[^<>]*>//g';
> >
> > return 0;
> >
> > }
> >
> >
> > 2012/4/13 codewalkertse 
> >
> > > 非常好的一个脚本 感谢分享
> > >
> > >
> > > 在 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?"
> > >> 你好吗?
> > >>
> > >> 也可以翻译中文。
> > >>
> > >> 原文地址 
> > >>
> > >
> > > 在 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?"
> > >> 你好吗?
> > >>
> > >> 也可以翻译中文。
> > >>
> > >> 原文地址 
> > >>
> > >
> > > 在 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?"
> > >> 你好吗?
> > >>
> > >> 也可以翻译中文。
> > >>
> > >> 原文地址 
> > >>
> > >
> > > 在 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的末尾
> > 

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

不错不错,正在使用中,感谢~``:)加个音标就更完美了,如果还能够实现发音。。

在 2012年5月12日 下午4:16,Hex Lee 写道:

> 大家好:
> [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>.*/\1/p';
>
> #examples
> echo $result \
>| sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
>| sed 's///g' \
>| sed 's/<\/em>//g' \
>| sed 's//\n/g' \
>| sed 's//\n/g' \
>| sed 's/<[^<>]*>//g';
>
> return 0;
>
> }
>
>
> 2012/4/13 codewalkertse 
>
> > 非常好的一个脚本 感谢分享
> >
> >
> > 在 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?"
> >> 你好吗?
> >>
> >> 也可以翻译中文。
> >>
> >> 原文地址 
> >>
> >
> > 在 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?"
> >> 你好吗?
> >>
> >> 也可以翻译中文。
> >>
> >> 原文地址 
> >>
> >
> > 在 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?"
> >> 你好吗?
> >>
> >> 也可以翻译中文。
> >>
> >> 原文地址 
> >>
> >
> > 在 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?"
> >> 你好吗?
> >>
> >> 也可以翻译中文。
> >>
> >> 原文地址 
> >>
> >
> > 在 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

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

挺不错的额~学习了~

在 2012年5月12日 下午4:44,Hex Lee  写道:
> Mac版本,因为unix 和 linux的sed命令有差异,注意换行符号的处理:
> # Mac Version
> # notic: ^M^L = Ctrl+v Ctrl+Enter Ctrl+v Ctrl+l
> ts(){
> result=`curl -s \
>"http://dict.cn/ws.php?utf8=true&q=$1"; `;
>
> echo $result | sed -E -n 's/.*([^<]+)<\/def>.*/\1/p';
>
> #examples
> echo $result \
>| sed -E -n 's/.*def> (.*<\/sent>).*/\1/p' \
>| sed 's///g' \
>| sed 's/<\/em>//g' \
>| sed 's//^M^L/g' \
>| sed 's//^M^L/g' \
>| sed 's/<[^<>]*>//g' ;
>
> return 0;
>
> }
>
> 在 2012年5月12日 下午4:16,Hex Lee 写道:
>
>> 大家好:
>> [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>.*/\1/p';
>>
>> #examples
>> echo $result \
>> | sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
>> | sed 's///g' \
>> | sed 's/<\/em>//g' \
>> | sed 's//\n/g' \
>> | sed 's//\n/g' \
>> | sed 's/<[^<>]*>//g';
>>
>> return 0;
>>
>> }
>>
>>
>> 2012/4/13 codewalkertse 
>>
>>> 非常好的一个脚本 感谢分享
>>>
>>>
>>> 在 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"
 \
  -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?"
 你好吗?

 也可以翻译中文。

 原文地址 

>>>
>>> 在 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"
 \
  -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?"
 你好吗?

 也可以翻译中文。

 原文地址 

>>>
>>> 在 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"
 \
  -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?"
 你好吗?

 也可以翻译中文。

 原文地址 

>>>
>>> 在 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"
 \
  -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.添加此脚

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

Mac版本,因为unix 和 linux的sed命令有差异,注意换行符号的处理:
# Mac Version
# notic: ^M^L = Ctrl+v Ctrl+Enter Ctrl+v Ctrl+l
ts(){
result=`curl -s \
"http://dict.cn/ws.php?utf8=true&q=$1"; `;

echo $result | sed -E -n 's/.*([^<]+)<\/def>.*/\1/p';

#examples
echo $result \
| sed -E -n 's/.*def> (.*<\/sent>).*/\1/p' \
| sed 's///g' \
| sed 's/<\/em>//g' \
| sed 's//^M^L/g' \
| sed 's//^M^L/g' \
| sed 's/<[^<>]*>//g' ;

return 0;

}

在 2012年5月12日 下午4:16,Hex Lee 写道:

> 大家好:
> [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>.*/\1/p';
>
> #examples
> echo $result \
> | sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
> | sed 's///g' \
> | sed 's/<\/em>//g' \
> | sed 's//\n/g' \
> | sed 's//\n/g' \
> | sed 's/<[^<>]*>//g';
>
> return 0;
>
> }
>
>
> 2012/4/13 codewalkertse 
>
>> 非常好的一个脚本 感谢分享
>>
>>
>> 在 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"
>>> \
>>>  -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?"
>>> 你好吗?
>>>
>>> 也可以翻译中文。
>>>
>>> 原文地址 
>>>
>>
>> 在 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"
>>> \
>>>  -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?"
>>> 你好吗?
>>>
>>> 也可以翻译中文。
>>>
>>> 原文地址 
>>>
>>
>> 在 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"
>>> \
>>>  -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?"
>>> 你好吗?
>>>
>>> 也可以翻译中文。
>>>
>>> 原文地址 
>>>
>>
>> 在 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"
>>> \
>>>  -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?"
>>> 你好吗?
>>>
>>> 也可以翻译中文。
>>>
>>> 原文地址 
>>>
>>
>> 在 2012年3月23日星期五UTC+8下午11时26分10秒,Hex Lee写道:
>>>
>>> t

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

大家好:
[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>.*/\1/p';

#examples
echo $result \
| sed -r -n 's/.*def> (.*<\/sent>).*/\1/p' \
| sed 's///g' \
| sed 's/<\/em>//g' \
| sed 's//\n/g' \
| sed 's//\n/g' \
| sed 's/<[^<>]*>//g';

return 0;

}


2012/4/13 codewalkertse 

> 非常好的一个脚本 感谢分享
>
>
> 在 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"
>> \
>>  -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?"
>> 你好吗?
>>
>> 也可以翻译中文。
>>
>> 原文地址 
>>
>
> 在 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"
>> \
>>  -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?"
>> 你好吗?
>>
>> 也可以翻译中文。
>>
>> 原文地址 
>>
>
> 在 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"
>> \
>>  -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?"
>> 你好吗?
>>
>> 也可以翻译中文。
>>
>> 原文地址 
>>
>
> 在 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"
>> \
>>  -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?"
>> 你好吗?
>>
>> 也可以翻译中文。
>>
>> 原文地址 
>>
>
> 在 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"
>> \
>>  -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?"
>> 你好吗?
>>
>> 也可以翻译中文。
>>
>> 原文地址