Sha256: 67724325fb6851598b29c052f65ea45f5764e993b68de29ad4eb93127dc64473

Contents?: true

Size: 867 Bytes

Versions: 16

Compression:

Stored size: 867 Bytes

Contents

module ActiveModel
  module Translation
    # CarDealer.sales_count -> s_('CarDealer|Sales count') -> 'Sales count' if no translation was found
    def human_attribute_name(attribute, *args)
      s_(gettext_translation_for_attribute_name(attribute))
    end

    def gettext_translation_for_attribute_name(attribute)
      attribute = attribute.to_s
      if attribute.ends_with?('_id')
        humanize_class_name(attribute)
      else
        "#{inheritance_tree_root(self)}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
      end
    end

    def inheritance_tree_root(aclass)
      return aclass unless aclass.respond_to?(:base_class)
      base = aclass.base_class
      base.superclass.abstract_class? ? base.superclass : base
    end

    def humanize_class_name(name=nil)
      name ||= self.to_s
      name.underscore.humanize
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
gettext_i18n_rails-1.3.2 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.3.1 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.3.0 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.2.3 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.2.2 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.2.1 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.2.0 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.1.0 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.5 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.4 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.3 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.2 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.1 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-1.0.0 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-0.10.1 lib/gettext_i18n_rails/active_model/translation.rb
gettext_i18n_rails-0.10.0 lib/gettext_i18n_rails/active_model/translation.rb