Module: Yandex::Translator::Translate

Included in:
Yandex::Translator
Defined in:
lib/yandex/translator/translate.rb

Overview

Translate module

Instance Method Summary collapse

Instance Method Details

#translate(args = {}) ⇒ Object

Translate text



6
7
8
9
10
11
12
13
# File 'lib/yandex/translator/translate.rb', line 6

def translate(args = {})
  check_args(text: args[:text], to: args[:to])
  translate_direction = args[:from].nil? ? args[:to] : "#{args[:from]}-#{args[:to]}"
  response = request('/translate', lang: translate_direction, text: args[:text])
  response.parsed_response
rescue YandexFailure => ex
  return { error: ex.message }
end