Skip to content

Commit

Permalink
Merge pull request #14 from KicksiteDev/master
Browse files Browse the repository at this point in the history
added optional format to translate method
  • Loading branch information
aegorov authored Mar 4, 2020
2 parents c30ab6f + 6bf52c8 commit 066fda8
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions lib/yandex/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ def get_langs
translator.get_langs
end

def translate(text, *lang)
translator.translate(text, *lang)
def translate(text, from: nil, to: nil)
translator.translate(text, from: from, to: to)
end

def detect(text)
Expand All @@ -51,13 +51,10 @@ def detect(text)
lang == '' ? nil : lang
end

def translate(text, *lang)
if lang.last.is_a?(Hash)
lang_options = lang.last
lang = [lang_options[:to], lang_options[:from]].compact
end
def translate(text, from: nil, to: nil, format: 'plain')
lang = (to.nil? && from.nil?) ? [] : [to, from].compact

options = { text: text, lang: lang.reverse.join('-') }
options = { text: text, lang: lang.reverse.join('-'), format: format }

result = visit('/translate', options)['text']

Expand Down

0 comments on commit 066fda8

Please sign in to comment.