Class: ActiveAdmin::Localizers::ResourceLocalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_admin/localizers/resource_localizer.rb

Class Method Summary collapse

Instance Method Summary collapse

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

.tObject


13
14
15
# File 'lib/active_admin/localizers/resource_localizer.rb', line 13

def translate(key, options)
  new(options.delete(:model_name), options.delete(:model)).translate(key, options)
end

.translate(key, options) ⇒ Object


10
11
12
# File 'lib/active_admin/localizers/resource_localizer.rb', line 10

def translate(key, options)
  new(options.delete(:model_name), options.delete(:model)).translate(key, options)
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, options = {})
  scope = options.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, **options.reverse_merge(model: @model, default: defaults, scope: "active_admin")
end