Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update translator.rb #13

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/yandex/translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ def detect(text)
lang == '' ? nil : lang
end

def translate(text, *lang)
def translate(text, *lang, format)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can provide default value 'plain' here

def translate(text, *lang, format = 'plain')

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome, this is cleaner

if lang.last.is_a?(Hash)
lang_options = lang.last
lang = [lang_options[:to], lang_options[:from]].compact
end

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

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

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

Expand Down