Module: ActiveModel::Translation
- Included in:
- ActiveRecord::Base
- Defined in:
- lib/gettext_i18n_rails/active_model/translation.rb
Instance Method Summary collapse
- #gettext_translation_for_attribute_name(attribute) ⇒ Object
-
#human_attribute_name(attribute, *args) ⇒ Object
CarDealer.sales_count -> s_(‘CarDealer|Sales count’) -> ‘Sales count’ if no translation was found.
- #humanize_class_name(name = nil) ⇒ Object
- #inheritance_tree_root(aclass) ⇒ Object
Instance Method Details
#gettext_translation_for_attribute_name(attribute) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/gettext_i18n_rails/active_model/translation.rb', line 8 def gettext_translation_for_attribute_name(attribute) attribute = attribute.to_s if attribute.end_with?('_id') humanize_class_name(attribute) else "#{inheritance_tree_root(self)}|#{attribute.split('.').map! {|a| a.humanize }.join('|')}" end end |
#human_attribute_name(attribute, *args) ⇒ Object
CarDealer.sales_count -> s_(‘CarDealer|Sales count’) -> ‘Sales count’ if no translation was found
4 5 6 |
# File 'lib/gettext_i18n_rails/active_model/translation.rb', line 4 def human_attribute_name(attribute, *args) s_(gettext_translation_for_attribute_name(attribute)) end |
#humanize_class_name(name = nil) ⇒ Object
31 32 33 34 |
# File 'lib/gettext_i18n_rails/active_model/translation.rb', line 31 def humanize_class_name(name=nil) name ||= self.to_s name.underscore.humanize end |
#inheritance_tree_root(aclass) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gettext_i18n_rails/active_model/translation.rb', line 17 def inheritance_tree_root(aclass) return aclass unless aclass.respond_to?(:base_class) base = aclass.base_class if base.superclass.abstract_class? if defined?(::ApplicationRecord) && base.superclass == ApplicationRecord base else base.superclass end else base end end |