google translator 0.2

简介:
过去写的那个利用google在线翻译的 小脚本工具一直在用,今天用的时候,突然想,我今年不是想加强下英语学习吗?那么把每天查过的单词保存下来,每天早上或者上班空闲期间花那么几分钟记忆复习下这些单词不是很好,毕竟技术性文章翻来覆去运用的单词就那么多,过去没有注意积累,导致常常还得重新查,所谓提高也就放在口头上了。说改就改,脚本语言改起来就是容易:

# 利用google在线翻译,翻译中文<->英文
#
author dennis
#
version 0.2
require  ' net/http '
$contents
= Hash.new
$dir
= " F:/English/ "
now
= Time.now
$today
= " #{now.year}#{now.month.to_s.rjust(2,'0')}#{now.day.to_s.rjust(2,'0')} "
def  translate
  txt
= STDIN.gets
  
if  txt.strip == ' e '   or  txt.strip == ' exit '
    
# 退出前保存
     if  $contents.size > 0 then
      File.open(
" #{$dir}#{$today}.txt " , " a+ " ) do  | file |
        $contents.each {
| key,value |  file.write(key.ljust( 20 ) + value.ljust( 20 ) + " \n " )}
      end
    end
    exit
  end
  temp
= txt.split( '   ' )
  
if  temp[ 1 ] == ' 1 '   or  temp.size == 1
    langpair
= ' en|zh-CN '
  
else
    langpair
= ' zh-CN|en '
  end
  begin 
    
# 使用代理  
     # $proxy_addr = '192.168.9.25'
    $proxy_port  =   8081
    $proxy_user
= ' test '
    $proxy_passwd
= ' test '
    
if  $proxy_addr
     response 
=  Net::HTTP.Proxy($proxy_addr,$proxy_port,$proxy_user,$proxy_passwd).post_form(URI.parse( " http://translate.google.com/translate_t " ),{ ' text ' => temp[0], ' langpair ' => langpair}) 
    
else
      response 
=  Net::HTTP.post_form(URI.parse( " http://translate.google.com/translate_t " ),{ ' text ' => temp[0], ' langpair ' => langpair}) 
    end
    response.body 
=~   /< textarea. * ?id = suggestion > (. * ?) < \ / textarea >/
  rescue  StandardError 
=> e
    $stderr.
print   " 错误: " + e
  
else
    result 
=  $ 1  
    puts 
' 翻译内容: ' + temp[0]
    puts 
' google返回: ' + result  if  result
    $contents[temp[0]]
= result
    puts 
' -------------------退出请打e或者exit--------------- '
    translate
  end
end
translate
文章转自庄周梦蝶  ,原文发布时间2008-02-14
目录
相关文章
|
数据可视化 定位技术 Sentinel
如何用Google Earth Engine快速、大量下载遥感影像数据?
【2月更文挑战第9天】本文介绍在谷歌地球引擎(Google Earth Engine,GEE)中,批量下载指定时间范围、空间范围的遥感影像数据(包括Landsat、Sentinel等)的方法~
4941 1
如何用Google Earth Engine快速、大量下载遥感影像数据?
|
编解码 人工智能 算法
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
Google Earth Engine——促进森林温室气体报告的全球时间序列数据集
279 0
|
编解码 人工智能 数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
Google Earth Engine(GEE)——全球道路盘查项目全球道路数据库
371 0
|
编解码
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
Open Google Earth Engine(OEEL)——matrixUnit(...)中产生常量影像
228 0
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
Google Earth Engine(GEE)——导出指定区域的河流和流域范围
792 0
|
传感器 编解码 数据处理
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
Open Google Earth Engine(OEEL)——哨兵1号数据的黑边去除功能附链接和代码
425 0
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
Google Earth Engine(GEE)——当加载图表的时候出现错误No features contain non-null values of “system:time_start“.
323 0
|
编解码 定位技术
Google Earth Engine(GEE)——导出后的影像像素不同于原始Landsat影像的分辨率(投影差异)
Google Earth Engine(GEE)——导出后的影像像素不同于原始Landsat影像的分辨率(投影差异)
531 0
|
机器学习/深度学习 算法 数据可视化
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
基于Google Earth Engine云平台构建的多源遥感数据森林地上生物量AGB估算模型含生物量模型应用APP
590 0

热门文章

最新文章