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

Introduce helper method for translating public locale names #2166

Closed
Closed
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
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 LocalesHelper

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

if entry.default_translation?
t('pageflow.admin.entry_translations.default_translation', display_locale:)
Expand Down
10 changes: 7 additions & 3 deletions app/helpers/pageflow/admin/locales_helper.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
module Pageflow
module Admin
module LocalesHelper
def locale_name_for(locale, i18n_key = 'pageflow.public._language')
I18n.t(i18n_key, locale: locale)
end

def available_locales_collection
locales_collection(Pageflow.config.available_locales, 'language')
end

def available_public_locales_collection
locales_collection(Pageflow.config.available_public_locales, 'pageflow.public._language')
locales_collection(Pageflow.config.available_public_locales)
end

private

def locales_collection(locales, i18n_key)
def locales_collection(locales, i18n_key = 'pageflow.public._language')
locales.map do |locale|
[I18n.t(i18n_key, locale: locale), locale.to_s]
[locale_name_for(locale, i18n_key), locale.to_s]
end
end
end
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 locale_name_for(translation.locale)

if translation.published_revision?
json.url social_share_entry_url(translation)
Expand Down
Loading