From d31297b557687b022e4534927237e4dfd1fdfd23 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 18 Dec 2020 11:23:03 +0000 Subject: [PATCH] DeepL: Fix single value translation 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 --- lib/i18n/tasks/translators/deepl_translator.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/i18n/tasks/translators/deepl_translator.rb b/lib/i18n/tasks/translators/deepl_translator.rb index 14d5488b..7bfd3c5f 100644 --- a/lib/i18n/tasks/translators/deepl_translator.rb +++ b/lib/i18n/tasks/translators/deepl_translator.rb @@ -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)