Skip to content

Commit

Permalink
Create helper for available_public_locales
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKuhn committed Oct 9, 2024
1 parent 71d6bfe commit f7f2ca6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
1 change: 1 addition & 0 deletions admins/pageflow/entry_templates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions app/helpers/pageflow/admin/locales_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions app/views/admin/entry_templates/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down
10 changes: 10 additions & 0 deletions spec/helpers/pageflow/admin/locales_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f7f2ca6

Please sign in to comment.