module Ransack::Translate

def attribute(key, options = {})

def attribute(key, options = {})
  unless context = options.delete(:context)
    raise ArgumentError, "A context is required to translate attributes"
  end
  original_name = key.to_s
  base_class = context.klass
  base_ancestors = base_class.ancestors.select {
    |x| x.respond_to?(:model_name)
  }
  attributes_str = original_name.dup # will be modified by ⬇
  predicate = Predicate.detect_and_strip_from_string!(attributes_str)
  attribute_names = attributes_str.split(/_and_|_or_/)
  combinator = attributes_str =~ /_and_/ ? :and : :or
  defaults = base_ancestors.map do |klass|
    "ransack.attributes.#{i18n_key(klass)}.#{original_name}".to_sym
  end
  defaults << options.delete(:default) if options[:default]
  translated_names = attribute_names.map do |name|
    attribute_name(context, name, options[:include_associations])
  end
  interpolations = {
    attributes: translated_names.join(" #{Translate.word(combinator)} ")
  }
  if predicate
    defaults << "%{attributes} %{predicate}".freeze
    interpolations[:predicate] = Translate.predicate(predicate)
  else
    defaults << "%{attributes}".freeze
  end
  options.reverse_merge! count: 1, default: defaults
  I18n.translate(defaults.shift, **options.merge(interpolations))
end