Sha256: 187f4787057c60c8bed021086ca1e7ff6e32f2656e5d9d72ab3600e174b8ec4b

Contents?: true

Size: 743 Bytes

Versions: 15

Compression:

Stored size: 743 Bytes

Contents

module ActiveModel
  class Name < String
    def human(options={})
      _(@klass.humanize_class_name)
    end
  end

  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
        "#{self}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}"
      end
    end

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

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
gettext_i18n_rails-0.9.1 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.9.0 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.8.0 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.7.2 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.7.1 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.7.0 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.6 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.5 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.4 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.3 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.2 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.6.1 lib/gettext_i18n_rails/active_model.rb
gettext_i18n_rails-0.5.4 lib/gettext_i18n_rails/active_model.rb
nulogy-gettext_i18n_rails-0.5.3.2 lib/gettext_i18n_rails/active_model.rb
nulogy-gettext_i18n_rails-0.5.3.1 lib/gettext_i18n_rails/active_model.rb