Skip to content

Commit

Permalink
DeepL: Convert locales to a compatible format
Browse files Browse the repository at this point in the history
  • Loading branch information
glebm committed Aug 3, 2018
1 parent 07af1c5 commit 49d6d2b
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/i18n/tasks/deepl_translation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand Down

0 comments on commit 49d6d2b

Please sign in to comment.