Sha256: 4a621b72eee45ff38bc9135b5ae1221c9a084168448d8626cae74f0ac0059a4e

Contents?: true

Size: 681 Bytes

Versions: 2

Compression:

Stored size: 681 Bytes

Contents

module GettextI18nRails::ActiveRecord
  # 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

  # method deprecated in Rails 3.1
  def human_name(*args)
    _(self.humanize_class_name)
  end

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

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

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
gettext_i18n_rails-0.5.2 lib/gettext_i18n_rails/active_record.rb
nulogy-gettext_i18n_rails-0.5.0.2 lib/gettext_i18n_rails/active_record.rb