Skip to content

Commit

Permalink
Merge pull request #2167 from DanielKuhn/public_locale_name_for-helper
Browse files Browse the repository at this point in the history
Use new public_locale_name_for-helper from updated PageflowI18n
  • Loading branch information
tf authored Oct 23, 2024
2 parents 30e8eb4 + 31473a4 commit f95d61f
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
1 change: 1 addition & 0 deletions admins/pageflow/sites.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ module Pageflow
controller do
helper Admin::CutoffModesHelper
helper Admin::FormHelper
helper Pageflow::PublicI18n::LocalesHelper

before_create do |site|
site.build_default_permalink_directory
Expand Down
7 changes: 3 additions & 4 deletions app/helpers/pageflow/admin/entry_translations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ module Pageflow
module Admin
# @api private
module EntryTranslationsHelper
include Pageflow::PublicI18n::LocalesHelper

def entry_translation_display_locale(entry)
display_locale = t(
'pageflow.public._language',
locale: (entry.published_revision || entry.draft).locale
)
display_locale = public_locale_name_for((entry.published_revision || entry.draft).locale)

if entry.default_translation?
t('pageflow.admin.entry_translations.default_translation', display_locale:)
Expand Down
16 changes: 7 additions & 9 deletions app/helpers/pageflow/admin/locales_helper.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
module Pageflow
module Admin
module LocalesHelper
include Pageflow::PublicI18n::LocalesHelper

def available_locales_collection
locales_collection(Pageflow.config.available_locales, 'language')
Pageflow.config.available_locales.map do |locale|
[I18n.t('language', locale: locale), locale.to_s]
end
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]
Pageflow.config.available_public_locales.map do |locale|
[public_locale_name_for(locale), locale.to_s]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/accounts/_entry_template_details.html.arb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extensible_attributes_table_for(entry_template,
entry_template.theme_name
end
row :default_locale, class: 'default_locale' do
t('pageflow.public._language', locale: entry_template.default_locale)
public_locale_name_for(entry_template.default_locale)
end
row :default_author, class: 'default_author'
row :default_publisher, class: 'default_publisher'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module EntryJsonSeedHelper
include Pageflow::EntriesHelper
include Pageflow::MetaTagsHelper
include Pageflow::SocialShareLinksHelper
include Pageflow::PublicI18n::LocalesHelper
include PageflowScrolled::I18nHelper
include PageflowScrolled::ThemesHelper

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
json.entry_translations do
json.array!(entry.translations(-> { preload(:site) }, include_noindex: true)) do |translation|
json.(translation, :id, :locale)
json.display_locale t('pageflow.public._language', locale: translation.locale)
json.display_locale public_locale_name_for(translation.locale)

if translation.published_revision?
json.url social_share_entry_url(translation)
Expand Down
2 changes: 1 addition & 1 deletion pageflow.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Gem::Specification.new do |s|
s.add_dependency 'http_accept_language', '~> 2.0'

# Shared translations
s.add_dependency 'pageflow-public-i18n', '~> 1.27'
s.add_dependency 'pageflow-public-i18n', '~> 1.28'

# Password encryption
s.add_dependency 'bcrypt', '~> 3.1.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Pageflow
describe Admin::EntryTemplatesTab, type: :view_component do
before do
helper.extend(ActiveAdmin::ViewHelpers)
helper.extend(Pageflow::PublicI18n::LocalesHelper)
end

it "has entries even if corresponding entry templates aren't created yet" do
Expand Down

0 comments on commit f95d61f

Please sign in to comment.