Class: ActiveAdmin::Localizers::ResourceLocalizer
- Inherits:
-
Object
- Object
- ActiveAdmin::Localizers::ResourceLocalizer
- Defined in:
- lib/active_admin/localizers/resource_localizer.rb
Class Method Summary collapse
Instance Method Summary collapse
- #array_to_key(*arr) ⇒ Object protected
-
#initialize(model_name, model = nil) ⇒ ResourceLocalizer
constructor
A new instance of ResourceLocalizer.
- #translate(key, options = {}) ⇒ Object (also: #t)
Constructor Details
#initialize(model_name, model = nil) ⇒ ResourceLocalizer
Returns a new instance of ResourceLocalizer.
16 17 18 19 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 16 def initialize(model_name, model = nil) @model_name = model_name @model = model || model_name.to_s.titleize end |
Class Method Details
.from_resource(resource_config) ⇒ Object
6 7 8 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 6 def from_resource(resource_config) new(resource_config.resource_name.i18n_key, resource_config.resource_label) end |
.t ⇒ Object
13 14 15 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 13 def translate(key, ) new(.delete(:model_name), .delete(:model)).translate(key, ) end |
.translate(key, options) ⇒ Object
10 11 12 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 10 def translate(key, ) new(.delete(:model_name), .delete(:model)).translate(key, ) end |
Instance Method Details
#array_to_key(*arr) ⇒ Object (protected)
31 32 33 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 31 def array_to_key(*arr) arr.flatten.compact.join(".").to_sym end |
#translate(key, options = {}) ⇒ Object Also known as: t
21 22 23 24 25 26 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 21 def translate(key, = {}) scope = .delete(:scope) specific_key = array_to_key("resources", @model_name, scope, key) defaults = [array_to_key(scope, key), key.to_s.titleize] ::I18n.t specific_key, **.reverse_merge(model: @model, default: defaults, scope: "active_admin") end |