Sha256: bed5b5152a9aaa5c8c96c640dc85e1c08a5a2da8df871697a37e65c4d3e596ae

Contents?: true

Size: 961 Bytes

Versions: 4

Compression:

Stored size: 961 Bytes

Contents

## Translate input strings by Yahoo Honyaku -- Soutaro Matsumoto

def yahoo(config, data)
  begin
    require 'rubygems'
  rescue LoadError
  end
  require 'mechanize'


  config = (config || { "translation" => "en=>ja" })

  trans = case config["translation"]
          when "en=>ja": "EJ"
          when "kr=>ja": "KJ"
          when "cn=>ja": "CJ"
          when "ja=>en": "JE"
          when "ja=>kr": "JK"
          when "ja=>cn": "JC"
          else
            return data
          end
  
  data.collect {|d|
    if d && d =~ /\S/
      agent = WWW::Mechanize.new
      start = agent.get("http://honyaku.yahoo.co.jp/")
      form = start.forms.last
      
      form.radiobuttons.each {|radio| radio.checked = (radio.value =~ /#{trans}/) ? true : false }
      form.fields.name("text").first.value = d
      
      result = agent.submit(form)
      result.forms.name("textFormEntry").fields.name("trn_text").value
    else
      d.to_s
    end
  }

end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yapra-0.1.3 legacy_plugins/Filter/Translations/yahoo.rb
yapra-0.1.0 legacy_plugins/Filter/Translations/yahoo.rb
yapra-0.1.1 legacy_plugins/Filter/Translations/yahoo.rb
yapra-0.1.2 legacy_plugins/Filter/Translations/yahoo.rb