Class: Decidim::Components::Namer

Inherits:
Object
  • Object
show all
Defined in:
decidim-core/lib/decidim/components/namer.rb

Overview

This class automatically names components for the given organization. In order to do so, it uses the i18n keys of the component, fallback to English, searching for the key `“decidim.components.<component name>.name”`

This is intended to be used from the component seeds section.

Examples:

Decidim::Component.create!(
  participatory_space: process,
  name: Decidim::Component::Namer.new(organization.available_locales, :my_component_name).i18n_name
  manifest_name: :my_component_name
)

Instance Method Summary collapse

Constructor Details

#initialize(locales, component_name) ⇒ Namer

Returns a new instance of Namer.


19
20
21
22
# File 'decidim-core/lib/decidim/components/namer.rb', line 19

def initialize(locales, component_name)
  @locales = locales
  @component_name = component_name
end

Instance Method Details

#i18n_nameObject


24
25
26
27
28
# File 'decidim-core/lib/decidim/components/namer.rb', line 24

def i18n_name
  locales.inject({}) do |names, locale|
    names.update(locale => I18n.t("decidim.components.#{component_name}.name", locale: locale))
  end
end