Sha256: 8c98243a630ff0b984e5305d7b51866c462c0532eed38b8c7122d632720e24bd

Contents?: true

Size: 609 Bytes

Versions: 3

Compression:

Stored size: 609 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

  # CarDealer -> _('car dealer')
  def human_name(*args)
    _(self.human_name_without_translation)
  end

  def human_name_without_translation
    self.to_s.underscore.gsub('_',' ')
  end

  private

  def gettext_translation_for_attribute_name(attribute)
    "#{self}|#{attribute.to_s.split('.').map! {|a| a.gsub('_',' ').capitalize }.join('|')}"
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gettext_i18n_rails-0.4.1 lib/gettext_i18n_rails/active_record.rb
gettext_i18n_rails-0.4.0 lib/gettext_i18n_rails/active_record.rb
gettext_i18n_rails-0.3.6 lib/gettext_i18n_rails/active_record.rb