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?