Module: I27r::GoogleTranslate
- Included in:
- Translator
- Defined in:
- lib/generators/i18n_translation/lib/translator.rb
Instance Method Summary collapse
Instance Method Details
#_translate(word, lang) ⇒ Object
5 6 7 8 9 |
# 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 |