From 49d6d2b6afc548b9753b6356a8b51d136b79ba10 Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Fri, 3 Aug 2018 13:56:13 +0100 Subject: [PATCH] DeepL: Convert locales to a compatible format --- lib/i18n/tasks/deepl_translation.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/i18n/tasks/deepl_translation.rb b/lib/i18n/tasks/deepl_translation.rb index 4dfa0f90..f34fd348 100644 --- a/lib/i18n/tasks/deepl_translation.rb +++ b/lib/i18n/tasks/deepl_translation.rb @@ -21,7 +21,7 @@ def initialize(*) end def translate_values(list, from:, to:, **options) - DeepL.translate(list, from, to, options).map(&:text) + DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options).map(&:text) end def options_for_translate_values(**options) @@ -58,6 +58,11 @@ def no_results_error_message private + # Convert 'es-ES' to 'ES' + def to_deepl_compatible_locale(locale) + locale.to_s.split('-', 2).first.upcase + end + def configure_api_key! api_key = @i18n_tasks.translation_config[:deepl_api_key] fail CommandError, I18n.t('i18n_tasks.deepl_translate.errors.no_api_key') if api_key.blank?