Module: Glib::ClassMethods
- Defined in:
- app/models/concerns/glib/enum_humanization.rb
Instance Method Summary collapse
- #glib_enum_hint(enum_name, enum_value) ⇒ Object
- #glib_enum_humanize(enum_name, enum_value, default_translation = nil, hint_suffix: false) ⇒ Object
Instance Method Details
#glib_enum_hint(enum_name, enum_value) ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'app/models/concerns/glib/enum_humanization.rb', line 38 def glib_enum_hint(enum_name, enum_value) i18n_key = self.model_name.i18n_key if (hint = I18n.t("dt_models.#{i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}.hint")).present? # text += " #{hint}" return hint end nil end |
#glib_enum_humanize(enum_name, enum_value, default_translation = nil, hint_suffix: false) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'app/models/concerns/glib/enum_humanization.rb', line 20 def glib_enum_humanize(enum_name, enum_value, default_translation = nil, hint_suffix: false) if enum_value translation_key = "activerecord.attributes.#{model_name.i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}" if default_translation.nil? && Rails.env.development? text = I18n.t(translation_key, raise: I18n::MissingTranslationData) else text = I18n.t(translation_key, default: default_translation) end if hint_suffix && (hint = glib_enum_hint(enum_name, enum_value)) text += " #{hint}" end text end end |