Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create helper for available_public_locales #2157

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading