Class: GoogleTranslate

Inherits:
Object
  • Object
show all
Defined in:
lib/generators/somatics/associated/associated_generator.rb,
lib/generators/somatics/attributes/attributes_generator.rb

Class Method Summary collapse

Class Method Details

.t(text, to_lang = 'zh-TW') ⇒ Object



9
10
11
12
# File 'lib/generators/somatics/associated/associated_generator.rb', line 9

def self.t(text,to_lang = 'zh-TW')
  uri = URI.parse('http://ajax.googleapis.com/ajax/services/language/translate')
  JSON.parse(Net::HTTP.post_form(uri, {"q" => text, "langpair" => "en|#{to_lang}", "v" => '1.0'}).body)['responseData']['translatedText'] rescue text.humanize
end