Module: RailsI18nExtended::ClassMethods

Defined in:
lib/rails_i18n_extended/object_extensions.rb

Instance Method Summary collapse

Instance Method Details

#t(params = {}) ⇒ Object



49
50
51
# File 'lib/rails_i18n_extended/object_extensions.rb', line 49

def t(params={})
  "activerecord.models.#{model_name.to_s.underscore.gsub('/', '_')}".t({count: 1}.update(params))
end

#t_action(panel, params = {}) ⇒ Object



65
66
67
# File 'lib/rails_i18n_extended/object_extensions.rb', line 65

def t_action(panel, params={})
  I18n.t("actions.#{I18n.model_key(self)}.#{panel}", **params)
end

#t_attr(attr, params = {}) ⇒ Object



77
78
79
# File 'lib/rails_i18n_extended/object_extensions.rb', line 77

def t_attr(attr, params={})
  I18n.t(I18n.attribute_key(self, attr), **params)
end

#t_confirm(panel, params = {}) ⇒ Object



69
70
71
# File 'lib/rails_i18n_extended/object_extensions.rb', line 69

def t_confirm(panel, params={})
  I18n.t("confirm.#{I18n.model_key(self)}.#{panel}", **params)
end

#t_custom_attr(attr, params = {}) ⇒ Object



81
82
83
# File 'lib/rails_i18n_extended/object_extensions.rb', line 81

def t_custom_attr(attr, params={})
  I18n.t(I18n.custom_attribute_key(self, attr), **params)
end

#t_enum(attr, value, params = {}) ⇒ Object



85
86
87
88
89
# File 'lib/rails_i18n_extended/object_extensions.rb', line 85

def t_enum(attr, value, params={})
  return unless value.present?

  I18n.t([I18n.attribute_key(self, attr.to_s.pluralize), value].join('.'), **params)
end

#t_message(panel, params = {}) ⇒ Object



73
74
75
# File 'lib/rails_i18n_extended/object_extensions.rb', line 73

def t_message(panel, params={})
  I18n.t("message.#{I18n.model_key(self)}.#{panel}", **params)
end

#t_panel(panel, params = {}) ⇒ Object



61
62
63
# File 'lib/rails_i18n_extended/object_extensions.rb', line 61

def t_panel(panel, params={})
  I18n.t("panels.#{I18n.model_key(self)}.#{panel}", **params)
end

#t_scope(scope, params = {}) ⇒ Object



57
58
59
# File 'lib/rails_i18n_extended/object_extensions.rb', line 57

def t_scope(scope, params={})
  I18n.t("activerecord.scopes.#{I18n.model_key(self)}.#{scope}", **params)
end

#tp(params = {}) ⇒ Object



53
54
55
# File 'lib/rails_i18n_extended/object_extensions.rb', line 53

def tp(params={})
  t(count: 2)
end