<commit_before>module Translations
  def text_for(field, locale)
    I18n.with_locale(locale) do
      "#{translatable_class.human_attribute_name(field)} #{language_texts[locale]}"
    end
  end

  def field_for(field, locale, visible: true)
    if translatable_class.name == "I18nContent"
      "contents_content_#{translatable.key}values_#{field}_#{locale}"
    else
      within(".translatable-fields[data-locale='#{locale}']") do
        find("input[id$='_#{field}'], textarea[id$='_#{field}']", visible: visible)[:id]
      end
    end
  end

  def fill_in_field(field, locale, with:)
    if input_fields.include?(field)
      fill_in field_for(field, locale), with: with
    else
      fill_in_textarea(field, textarea_fields[field], locale, with: with)
    end
  end

  def fill_in_textarea(field, textarea_type, locale, with:)
    if textarea_type == :markdownit
      click_link class: "fullscreen-toggle"
      fill_in field_for(field, locale), with: with
      click_link class: "fullscreen-toggle"
    elsif textarea_type == :ckeditor
      fill_in_ckeditor field_for(field, locale, visible: false), with: with
    end
  end

  def expect_page_to_have_translatable_field(field, locale, with:)
    if input_fields.include?(field)
      if translatable_class.name == "I18nContent" && with.blank?
        expect(page).to have_field field_for(field, locale)
      else
        expect(page).to have_field field_for(field, locale), with: with
      end
    else
      textarea_type = textarea_fields[field]

      if textarea_type == :markdownit
        click_link class: "fullscreen-toggle"
        expect(page).to have_field field_for(field, locale), with: with
        click_link class: "fullscreen-toggle"
      elsif textarea_type == :ckeditor
        within("div.js-globalize-attribute[data-locale='#{locale}'] .ckeditor [id$='#{field}']") do
          # Wait longer for iframe initialization
          expect(page).to have_selector "iframe.cke_wysiwyg_frame", wait: 5
          within_frame(textarea_fields.keys.index(field)) { expect(page).to have_content with }
        end
      end
    end
  end

  def front_end_path_to_visit?(path)
    path[/admin|managment|valuation/].blank?
  end
end<commit_msg>Add reusable methods to common actions translations module<commit_after>module Translations
  def text_for(field, locale)
    I18n.with_locale(locale) do
      "#{translatable_class.human_attribute_name(field)} #{language_texts[locale]}"
    end
  end

  def field_for(field, locale, visible: true)
    if translatable_class.name == "I18nContent"
      "contents_content_#{translatable.key}values_#{field}_#{locale}"
    else
      within(".translatable-fields[data-locale='#{locale}']") do
        find("input[id$='_#{field}'], textarea[id$='_#{field}']", visible: visible)[:id]
      end
    end
  end

  def fill_in_field(field, locale, with:)
    if input_fields.include?(field)
      fill_in field_for(field, locale), with: with
    else
      fill_in_textarea(field, textarea_fields[field], locale, with: with)
    end
  end

  def fill_in_textarea(field, textarea_type, locale, with:)
    if textarea_type == :markdownit
      click_link class: "fullscreen-toggle"
      fill_in field_for(field, locale), with: with
      click_link class: "fullscreen-toggle"
    elsif textarea_type == :ckeditor
      fill_in_ckeditor field_for(field, locale, visible: false), with: with
    end
  end

  def expect_page_to_have_translatable_field(field, locale, with:)
    if input_fields.include?(field)
      if translatable_class.name == "I18nContent" && with.blank?
        expect(page).to have_field field_for(field, locale)
      else
        expect(page).to have_field field_for(field, locale), with: with
      end
    else
      textarea_type = textarea_fields[field]

      if textarea_type == :markdownit
        click_link class: "fullscreen-toggle"
        expect(page).to have_field field_for(field, locale), with: with
        click_link class: "fullscreen-toggle"
      elsif textarea_type == :ckeditor
        within("div.js-globalize-attribute[data-locale='#{locale}'] .ckeditor [id$='#{field}']") do
          # Wait longer for iframe initialization
          expect(page).to have_selector "iframe.cke_wysiwyg_frame", wait: 5
          within_frame(textarea_fields.keys.index(field)) { expect(page).to have_content with }
        end
      end
    end
  end

  def front_end_path_to_visit?(path)
    path[/admin|managment|valuation/].blank?
  end

  def expect_to_have_language(language)
    expect(page).to have_select :select_language, with_options: [language]
  end

  def expect_not_to_have_language(language)
    expect(page).not_to have_select :select_language, with_options: [language]
  end

  def expect_to_have_language_selected(language)
    expect(page).to have_select :select_language, selected: language
  end
end
{'fraction_non_alphanumeric': 0.11079077429983525, 'fraction_numerical': 0.002883031301482702, 'mean_word_length': 3.780511811023622, 'pattern_counts': {'":': 0, '<': 3, '<?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': '6805136', 'n_tokens_mistral': 1580, 'n_tokens_neox': 1552, 'n_words': 330}