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

    before_action :set_locale, only: [:admin]

    helper_method :show_images?

    def save
      create_or_update_translation(params[:value])
      render(json: {})

    end

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

    def upload
      save_file
      file_path = ["/#{conf.save_images_path}", random_file_name].join('/')
      create_or_update_translation(file_path)
      redirect_to params[:redirect_to]
    end

    private

    def create_or_update_translation(value)<commit_msg>preload keys from DB<commit_after>module EditI18nDatabaseTranslations
  class TranslationController < ActionController::Base
    include EditI18nDatabaseTranslations::ControllerModule

    before_action :set_locale, only: [:admin]

    helper_method :show_images?

    def save
      create_or_update_translation(params[:value])
      render(json: {})

    end

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

    def upload
      save_file
      file_path = ["/#{conf.save_images_path}", random_file_name].join('/')
      create_or_update_translation(file_path)
      redirect_to params[:redirect_to]
    end

    private

    def load_translations_keys_from_db
      keys = Translation
             .where(locale: I18n.locale)
             .pluck(:key)

      if show_images?
        keys.select! do |key|
          conf.check_images_proc.call(key)
        end
      end

      @list_of_keys = @list_of_keys + keys
      @list_of_keys.uniq!
    end

    def create_or_update_translation(value)
{'fraction_non_alphanumeric': 0.07802874743326489, 'fraction_numerical': 0.007186858316221766, 'mean_word_length': 3.311946902654867, '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': '4625727', 'n_tokens_mistral': 618, 'n_tokens_neox': 589, 'n_words': 103}