翻译脚本总结

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙

翻译脚本总结

#1

帖子 eexpress » 2009-07-10 13:27

一个 stardict 的单词翻译,一个 google translate 的全文翻译。
带 -n 是屏幕的notify 提示。否则是cli输出,用于irc的bot翻译。无参数时,自动取鼠标选择的文字。带 -1 是为了bot服务的。

代码: 全选

☎ cat sdcv.pl 
#!/usr/bin/perl
use Getopt::Long;

# 参数:单行输出选择。屏幕提示输出选择。
GetOptions('1' => \$oneline, 'n'=>\$notify);

my $out,$in;
# 无参数时,使用剪贴板内容。
$in=$ARGV[0]; if(!$in){$in=`xsel -o`;} if(!$in){exit;}
open(SDCV,"sdcv -n $in|");
my $r;
while($l=<SDCV>){
if($l!~/^$/){$r=$l;chomp($r);$r=~s/-->//;}
else{$out="$r --> ";last;}
}
while($l=<SDCV>){
if($l=~/相关|^$/){
close(SDCV);
if($notify){`notify-send -i '/home/exp/媒体/128软件png/pidgin.png' 'sdcv翻译' "$out"`;}
else{print $out;}
exit;
}
chomp($l) if($oneline);
$out.=" ► $l";
}

代码: 全选

☎ cat g-translate.pl 
#!/usr/bin/perl

use Getopt::Long;
GetOptions('n'=>\$notify);
my $out,$in,$str;
# 无参数时,使用剪贴板内容。
$in=join('+',@ARGV);if(!$in){$in=`xsel -o`;} if(!$in){exit;}
$in=`echo "$in"|uni2ascii -a J -s`;
$in=~s/ /+/g; $in=~s/["']//g;
chomp $in;
if($in=~/%/){$str="zh-CN%7Cen";}else{$str="en%7Czh-CN";}
$out="curl -e http://www.my-ajax-site.com 'http://ajax.googleapis.com/ajax/services/language/translate?v=1.0&q=$in&langpair=$str' 2>/dev/null";
$out=`$out`;
$out=~/translatedText":"(.*?)"/;
if($notify){`notify-send 'google翻译' "$1"`;}
else{print $1;}
● 鸣学
头像
nuanhuai
帖子: 7813
注册时间: 2009-03-10 13:04

Re: 翻译脚本总结

#2

帖子 nuanhuai » 2009-07-10 13:30

留个记号 :em11
头像
Ur@nus
帖子: 622
注册时间: 2006-12-01 23:02

Re: 翻译脚本总结

#3

帖子 Ur@nus » 2009-07-10 14:23

大仙,你表达什么主题?我以为你要开班呢,赶紧占了个前排,没想到只讲例子。 :em06
头像
spy8888
帖子: 65
注册时间: 2005-12-26 19:54

Re: 翻译脚本总结

#4

帖子 spy8888 » 2009-11-06 19:35

请问LZ怎么设置热建,compiz里设置了没反映
回复