Module: Glib::ClassMethods
- Defined in:
- app/models/concerns/glib/enum_humanization.rb
Instance Method Summary collapse
- #glib_enum_hint(enum_name, enum_value, i18n_args: {}) ⇒ Object
- #glib_enum_humanize(enum_name, enum_value, default_translation = nil, hint_suffix: false, i18n_args: {}) ⇒ Object
Instance Method Details
#glib_enum_hint(enum_name, enum_value, i18n_args: {}) ⇒ 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_args: {}) i18n_key = self.model_name.i18n_key if (hint = I18n.t("dt_models.#{i18n_key}.#{enum_name.to_s.pluralize}.#{enum_value}.hint", **i18n_args)).present? # text += " #{hint}" return hint end nil end |
#glib_enum_humanize(enum_name, enum_value, default_translation = nil, hint_suffix: false, i18n_args: {}) ⇒ 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, i18n_args: {}) 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? || Rails.env.test?) text = I18n.t(translation_key, **i18n_args.merge(raise: I18n::MissingTranslationData)) else text = I18n.t(translation_key, **i18n_args.merge(default: default_translation)) end if hint_suffix && (hint = glib_enum_hint(enum_name, enum_value, i18n_args: i18n_args)) text += " #{hint}" end text end end |