Module: EasyTranslate::Translation
- Included in:
- EasyTranslate
- Defined in:
- lib/easy_translate/translation.rb
Defined Under Namespace
Classes: TranslationRequest
Instance Method Summary collapse
Instance Method Details
#translate(texts, options = {}, http_options = {}) ⇒ String, Array
Translate text
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/easy_translate/translation.rb', line 14 def translate(texts, = {}, ={}) request = TranslationRequest.new(texts, , ) # Turn the response into an array of translations raw = request.perform_raw translations = JSON.parse(raw)['data']['translations'].map do |res| res['translatedText'] end # And then return, if they only asked for one, only give one back request.multi? ? translations : translations.first end |