Skip to content

Commit

Permalink
DeepL: Fix single value translation
Browse files Browse the repository at this point in the history
DeepL return type is polymorphic and returns a single value instead of
an array when given a single element array.

Thanks to @lukasbischof, @jesusalc, @schmijos

Fixes #363
Fixes #347
  • Loading branch information
glebm committed Dec 18, 2020
1 parent ef5d14a commit d31297b
Showing 1 changed file with 6 additions and 1 deletion.
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)
result = DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options).map(&:text)
if result.is_a?(DeepL::Resources::Text)
result.text
else
result.map(&:text)
end
end

def options_for_translate_values(**options)
Expand Down

0 comments on commit d31297b

Please sign in to comment.