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

deepl plural and singular response handling #347

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/i18n/tasks/translators/deepl_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ def initialize(*)
protected

def translate_values(list, from:, to:, **options)
DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options).map(&:text)
deepl = DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options)
if deepl.respond_to? 'map'
Copy link
Owner

Choose a reason for hiding this comment

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

Does it respond with a string when there is only one element in the list?
If so, it'd be cleaner to check the list instead of checking the result: consider what happens if a later version of Ruby adds a map method to String

Choose a reason for hiding this comment

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

What about using Ruby goodness?

result = DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options)
[*result].map(&:text)

The splat operator would leave it all to Ruby ;-)

deepl.map(&:text)
else
[deepl.text]
end
end

def options_for_translate_values(**options)
Expand Down