Class: Decidim::Features::Namer
- Inherits:
-
Object
- Object
- Decidim::Features::Namer
- Defined in:
- lib/decidim/features/namer.rb
Overview
This class automatically names features for the given organization. In order to do so, it uses the i18n keys of the feature, fallback to English, searching for the key ‘“decidim.features.<feature name>.name”`
This is intended to be used from the feature seeds section.
Examples:
Decidim::Feature.create!(
participatory_process: process,
name: Decidim::Feature::Namer.new(organization.available_locales, :my_feature_name).i18n_name
manifest_name: :my_feature_name
)
Instance Method Summary collapse
- #i18n_name ⇒ Object
-
#initialize(locales, feature_name) ⇒ Namer
constructor
A new instance of Namer.
Constructor Details
#initialize(locales, feature_name) ⇒ Namer
Returns a new instance of Namer.
19 20 21 22 |
# File 'lib/decidim/features/namer.rb', line 19 def initialize(locales, feature_name) @locales = locales @feature_name = feature_name end |
Instance Method Details
#i18n_name ⇒ Object
24 25 26 27 28 |
# File 'lib/decidim/features/namer.rb', line 24 def i18n_name locales.inject({}) do |names, locale| names.update(locale => I18n.t("decidim.features.#{feature_name}.name", locale: locale)) end end |