<commit_before>module EditI18nDatabaseTranslations
  class TranslationController < ActionController::Base
    include EditI18nDatabaseTranslations::ControllerModule

    before_action :set_locale, only: [:admin]

    def save
      if translation
        translation.update(value: params[:value])
      else
        Translation.create(locale: I18n.locale,
                           key: params[:key],
                           value: params[:value])
      end
      I18n.reload!
      return render(json: {})
    end

    def admin
      @list_of_keys = []
      update_list_of_keys('', allowed_translations)
      render template: 'edit_i18n_database_translations/admin.html.erb'
    end

    private

    def are_you_i18n_editor?
      true
    end

    def update_list_of_keys(prefix, x)
      if x.is_a? Hash
        if (not prefix.empty?)
            prefix += "."
        end
        x.each {|key, value|
          update_list_of_keys(prefix + key.to_s, value)
        }
      else
        @list_of_keys.push(prefix)
      end
    end

    def translation
      @translation ||= Translation.where(key: params[:key], locale: params[:locale]).first
    end

    def allowed_keys
      EditI18nDatabaseTranslations.config.allowed_keys
    end

    def all_translations
      I18n.t('.')
    end

    def allowed_translations
      all_translations.select { |key, _| allowed_keys.include?(key) }
    end

    def set_locale
      I18n.locale = params[:locale] || I18n.default_locale
    end
  end
end<commit_msg>fixed saving texts with locale<commit_after>module EditI18nDatabaseTranslations
  class TranslationController < ActionController::Base
    include EditI18nDatabaseTranslations::ControllerModule

    before_action :set_locale, only: [:admin]

    def save
      if translation
        translation.update(value: params[:value])
      else
        Translation.create(locale: params[:locale],
                           key: prefix,
                           value: params[:value])
      end
      I18n.reload!
      return render(json: {})
    end

    def admin
      @list_of_keys = []
      update_list_of_keys('', allowed_translations)
      render template: 'edit_i18n_database_translations/admin.html.erb'
    end

    private

    def are_you_i18n_editor?
      true
    end

    def update_list_of_keys(prefix, x)
      if x.is_a? Hash
        if (not prefix.empty?)
            prefix += "."
        end
        x.each {|key, value|
          update_list_of_keys(prefix + key.to_s, value)
        }
      else
        @list_of_keys.push(prefix)
      end
    end

    def translation
      @translation ||= Translation.where(key: params[:key], locale: params[:locale]).first
    end

    def allowed_keys
      EditI18nDatabaseTranslations.config.allowed_keys
    end

    def all_translations
      I18n.t('.')
    end

    def allowed_translations
      all_translations.select { |key, _| allowed_keys.include?(key) }
    end

    def set_locale
      I18n.locale = params[:locale] || I18n.default_locale
    end

    def prefix
      params[:key].to_s
    end
  end
end
{'fraction_non_alphanumeric': 0.08562197092084006, 'fraction_numerical': 0.012277867528271405, 'mean_word_length': 2.258947368421053, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5998902', 'n_tokens_mistral': 971, 'n_tokens_neox': 924, 'n_words': 195}