<commit_before># loading all the locales has a significant (>30%) impact on the speed of initializing canvas
# so we skip it in situations where we don't need the locales, such as in development mode and in rails console
skip_locale_loading = (Rails.env.development? || Rails.env.test? || $0 == 'irb') && !ENV['RAILS_LOAD_ALL_LOCALES']
load_path = Rails.application.config.i18n.railties_load_path
if skip_locale_loading
  load_path.replace(load_path.grep(%r{/(locales|en)\.yml\z}))
else
  load_path << (Rails.root + "config/locales/locales.yml").to_s # add it at the end, to trump any weird/invalid stuff in locale-specific files
end

I18n.backend = I18nema::Backend.new
I18nema::Backend.send(:include, I18n::Backend::Fallbacks)
I18n.backend.init_translations

I18n.enforce_available_locales = true

I18nliner.infer_interpolation_values = false

unless CANVAS_RAILS3
  module I18nliner
    module RehashArrays
      def infer_pluralization_hash(default, *args)
        if default.is_a?(Array) && default.all?{|a| a.is_a?(Array) && a.size == 2 && a.first.is_a?(Symbol)}
          # this was a pluralization hash but rails 4 made it an array in the view helpers
          return Hash[default]
        end
        super
      end
    end
    CallHelpers.extend(RehashArrays)
  end
end

if ENV['LOLCALIZE']
  require 'i18n_tasks'
  I18n.send :extend, I18nTasks::Lolcalize
end

module I18nUtilities
  def before_label(text_or_key, default_value = nil, *args)
    if default_value
      text_or_key = "labels.#{text_or_key}" unless text_or_key.to_s =~ /\A#/
      text_or_key = I18n.t(text_or_key, default_value, *args)
    end
    I18n.t("#before_label_wrapper", "%{text}:", :text => text_or_key)
  end

  def _label_symbol_translation(method, text, options)
    if text.is_a?(Hash)
      options = text
      text = nil
    end
    text = method if text.nil? && method.is_a?(Symbol)
    if text.is_a?(Symbol)
      text = "labels.#{text}" unless text.to_s =~ /\A#/
      text = t(text, options.delete(:en))
    end
    text = before_label(text) if options.delete(:before)
    return text, options
  end
end

ActionView::Base.send(:include, I18nUtilities)
ActionView::Helpers::FormHelper.send(:include, I18nUtilities)
ActionView::Helpers::FormHelper.module_eval do
  # a convenience method to put the ":" after the label text (or do whatever
  # the selected locale dictates)
  def blabel(object_name, method, text = nil, options = {})
    if text.is_a?(Hash)<commit_msg>fix translations in before_labels<commit_after># loading all the locales has a significant (>30%) impact on the speed of initializing canvas
# so we skip it in situations where we don't need the locales, such as in development mode and in rails console
skip_locale_loading = (Rails.env.development? || Rails.env.test? || $0 == 'irb') && !ENV['RAILS_LOAD_ALL_LOCALES']
load_path = Rails.application.config.i18n.railties_load_path
if skip_locale_loading
  load_path.replace(load_path.grep(%r{/(locales|en)\.yml\z}))
else
  load_path << (Rails.root + "config/locales/locales.yml").to_s # add it at the end, to trump any weird/invalid stuff in locale-specific files
end

I18n.backend = I18nema::Backend.new
I18nema::Backend.send(:include, I18n::Backend::Fallbacks)
I18n.backend.init_translations

I18n.enforce_available_locales = true

I18nliner.infer_interpolation_values = false

unless CANVAS_RAILS3
  module I18nliner
    module RehashArrays
      def infer_pluralization_hash(default, *args)
        if default.is_a?(Array) && default.all?{|a| a.is_a?(Array) && a.size == 2 && a.first.is_a?(Symbol)}
          # this was a pluralization hash but rails 4 made it an array in the view helpers
          return Hash[default]
        end
        super
      end
    end
    CallHelpers.extend(RehashArrays)
  end
end

if ENV['LOLCALIZE']
  require 'i18n_tasks'
  I18n.send :extend, I18nTasks::Lolcalize
end

module I18nUtilities
  def before_label(text_or_key, default_value = nil, *args)
    if default_value
      text_or_key = "labels.#{text_or_key}" unless text_or_key.to_s =~ /\A#/
      text_or_key = respond_to?(:t) ? t(text_or_key, default_value, *args) : I18n.t(text_or_key, default_value, *args)
    end
    I18n.t("#before_label_wrapper", "%{text}:", :text => text_or_key)
  end

  def _label_symbol_translation(method, text, options)
    if text.is_a?(Hash)
      options = text
      text = nil
    end
    text = method if text.nil? && method.is_a?(Symbol)
    if text.is_a?(Symbol)
      text = "labels.#{text}" unless text.to_s =~ /\A#/
      text = t(text, options.delete(:en))
    end
    text = before_label(text) if options.delete(:before)
    return text, options
  end
end

ActionView::Base.send(:include, I18nUtilities)
ActionView::Helpers::FormHelper.send(:include, I18nUtilities)
ActionView::Helpers::FormHelper.module_eval do
  # a convenience method to put the ":" after the label text (or do whatever
  # the selected locale dictates)
  def blabel(object_name, method, text = nil, options = {})
    if text.is_a?(Hash)
{'fraction_non_alphanumeric': 0.11479337193052505, 'fraction_numerical': 0.01597125174685566, 'mean_word_length': 4.050403225806452, 'pattern_counts': {'":': 2, '<': 7, '<?xml version=': 0, '>': 7, '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': '4909125', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1744, 'n_words': 436}