<commit_before># frozen_string_literal: true

require 'i18n/tasks/translators/base_translator'

module I18n::Tasks::Translators
  class DeeplTranslator < BaseTranslator
    def initialize(*)
      begin
        require 'deepl'
      rescue LoadError
        raise ::I18n::Tasks::CommandError, "Add gem 'deepl-rb' to your Gemfile to use this command"
      end
      super
      configure_api_key!
    end

    protected

    def translate_values(list, from:, to:, **options)
      DeepL.translate(list, to_deepl_compatible_locale(from), to_deepl_compatible_locale(to), options).map(&:text)
    end

    def options_for_translate_values(**options)
      { ignore_tags: %w[i18n] }.merge(options)
    end

    def options_for_html
      { tag_handling: 'xml' }
    end

    def options_for_plain
      { preserve_formatting: true }
    end
<commit_msg>DeepL: Fix single value translation<commit_after># frozen_string_literal: true

require 'i18n/tasks/translators/base_translator'

module I18n::Tasks::Translators
  class DeeplTranslator < BaseTranslator
    def initialize(*)
      begin
        require 'deepl'
      rescue LoadError
        raise ::I18n::Tasks::CommandError, "Add gem 'deepl-rb' to your Gemfile to use this command"
      end
      super
      configure_api_key!
    end

    protected

    def translate_values(list, from:, to:, **options)
      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)
      { ignore_tags: %w[i18n] }.merge(options)
    end

    def options_for_html
      { tag_handling: 'xml' }
    end

    def options_for_plain
      { preserve_formatting: true }
    end

{'fraction_non_alphanumeric': 0.09332609875203472, 'fraction_numerical': 0.008681497558328812, 'mean_word_length': 3.171945701357466, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2550474', 'n_tokens_mistral': 617, 'n_tokens_neox': 587, 'n_words': 131}