From f5f7e7bd2e3165ceb2b3daefe5de6752a124f69f Mon Sep 17 00:00:00 2001 From: Daniel Kuhn Date: Wed, 9 Oct 2024 13:35:14 +0200 Subject: [PATCH] Create helper for available_public_locales --- admins/pageflow/entry_templates.rb | 1 + app/helpers/pageflow/admin/locales_helper.rb | 14 ++++++++++++-- app/views/admin/entry_templates/_form.html.erb | 4 +--- spec/helpers/pageflow/admin/locales_helper_spec.rb | 10 ++++++++++ 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/admins/pageflow/entry_templates.rb b/admins/pageflow/entry_templates.rb index d0a7963de9..7f034268f3 100644 --- a/admins/pageflow/entry_templates.rb +++ b/admins/pageflow/entry_templates.rb @@ -14,6 +14,7 @@ module Pageflow controller do helper Pageflow::Admin::FormHelper helper Pageflow::Admin::WidgetsHelper + helper Pageflow::Admin::LocalesHelper def index redirect_to redirect_path diff --git a/app/helpers/pageflow/admin/locales_helper.rb b/app/helpers/pageflow/admin/locales_helper.rb index a8cf63354b..0c9456faa9 100644 --- a/app/helpers/pageflow/admin/locales_helper.rb +++ b/app/helpers/pageflow/admin/locales_helper.rb @@ -2,8 +2,18 @@ module Pageflow module Admin module LocalesHelper def available_locales_collection - Pageflow.config.available_locales.map do |locale| - [I18n.t('language', locale: locale), locale.to_s] + locales_collection(Pageflow.config.available_locales, 'language') + end + + def available_public_locales_collection + locales_collection(Pageflow.config.available_public_locales, 'pageflow.public._language') + end + + private + + def locales_collection(locales, i18n_key) + locales.map do |locale| + [I18n.t(i18n_key, locale: locale), locale.to_s] end end end diff --git a/app/views/admin/entry_templates/_form.html.erb b/app/views/admin/entry_templates/_form.html.erb index c11a44c128..80fabcc72c 100644 --- a/app/views/admin/entry_templates/_form.html.erb +++ b/app/views/admin/entry_templates/_form.html.erb @@ -9,9 +9,7 @@ <%= f.input :default_locale, as: :select, include_blank: false, - collection: Pageflow.config.available_public_locales.map{ |locale| - [t('pageflow.public._language', locale: locale), locale.to_s] - }, + collection: available_public_locales_collection, hint: t('pageflow.admin.sites.default_locale_hint') %> <%= f.input :default_author, hint: t('pageflow.admin.sites.default_author_hint'), diff --git a/spec/helpers/pageflow/admin/locales_helper_spec.rb b/spec/helpers/pageflow/admin/locales_helper_spec.rb index 16ed6721d0..a214400a6f 100644 --- a/spec/helpers/pageflow/admin/locales_helper_spec.rb +++ b/spec/helpers/pageflow/admin/locales_helper_spec.rb @@ -12,6 +12,16 @@ module Admin expect(pairs).to eq([['Deutsch', 'de']]) end end + + describe '#available_public_locales_collection' do + it 'returns collection of configured available public locales for select' do + Pageflow.config.available_public_locales = [:de, :en, :fr] + + pairs = available_public_locales_collection + + expect(pairs).to eq([['Deutsch', 'de'], ['English', 'en'], ["Français", "fr"]]) + end + end end end end