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.
15 16 17 18 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 15 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
5 6 7 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 5 def from_resource(resource_config) new(resource_config.resource_name.i18n_key, resource_config.resource_label) end |
.t ⇒ Object
12 13 14 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 12 def translate(key, ) new(.delete(:model_name), .delete(:model)).translate(key, ) end |
.translate(key, options) ⇒ Object
9 10 11 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 9 def translate(key, ) new(.delete(:model_name), .delete(:model)).translate(key, ) end |
Instance Method Details
#array_to_key(*arr) ⇒ Object (protected)
30 31 32 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 30 def array_to_key(*arr) arr.flatten.compact.join('.').to_sym end |
#translate(key, options = {}) ⇒ Object Also known as: t
20 21 22 23 24 25 |
# File 'lib/active_admin/localizers/resource_localizer.rb', line 20 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 |