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.


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

.tObject


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

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

.translate(key, options) ⇒ Object


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

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)


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, 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