module I27r::GoogleTranslate

Public Instance Methods

_translate(word, lang) click to toggle source
# File lib/generators/i18n_translation/lib/translator.rb, line 5
def _translate(word, lang)
  w = CGI.escape ActiveSupport::Inflector.humanize(word)
  text = Net::HTTP.get URI("https://translate.google.com/translate_a/single?client=gtx&sl=en&tl=#{lang}&dt=t&q=#{w}")
  text.scan(/"(.*?)"/).first.first.tap {|t| t.force_encoding(Encoding::UTF_8) if t.respond_to? :force_encoding}
end