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 cb9a10c commit 54abe65
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
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 54abe65

Please sign in to comment.