Sha256: 1851c45a7f1d99496c43068b217fb3ccf7dea41875ab6e349a4ccc36f14c6908

Contents?: true

Size: 831 Bytes

Versions: 10

Compression:

Stored size: 831 Bytes

Contents

class MicrosoftTranslator
  CONFIG = YAML.load_file("./config/idiom.yml")
    
  class << self
    def t(value, code)
      value = URI.encode(value)
      # "http://api.microsofttranslator.com/V2/Http.svc/Translate?to=#{code}&text=#{}&appId=2CEF8B6B9CA38C6C8355B154C760C28A66E4339F"
      
      appId = CONFIG["appId"]
      url = "http://api.microsofttranslator.com/V2/Http.svc/Translate?to=#{code}&text=#{value}&appId=#{appId}"
      result = Net::HTTP.get(URI.parse(url))
      
      if result =~ /<string xmlns=\"http:\/\/schemas.microsoft.com\/2003\/10\/Serialization\/\">(.*)<\/string>/
        output = $1
      end
      if result =~ /Message: (.*)/
        $stdout.puts(result)
      end
      if result =~ /AppId is over the quota/
        raise "AppId is over the quota"
      end
      output.to_s
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
idiom-0.7.3 lib/idiom/microsoft_translator.rb
idiom-0.7.2 lib/idiom/microsoft_translator.rb
idiom-0.7.1 lib/idiom/microsoft_translator.rb
idiom-0.7.0 lib/idiom/microsoft_translator.rb
idiom-0.6.0 lib/idiom/microsoft_translator.rb
idiom-0.5.5 lib/idiom/microsoft_translator.rb
idiom-0.5.4 lib/idiom/microsoft_translator.rb
idiom-0.5.3 lib/idiom/microsoft_translator.rb
idiom-0.5.2 lib/idiom/microsoft_translator.rb
idiom-0.5.1 lib/idiom/microsoft_translator.rb