From 0fe130f431f02ed385fb502ac380fe387aea6ac2 Mon Sep 17 00:00:00 2001 From: Daniel Kuhn Date: Mon, 21 Oct 2024 16:42:47 +0200 Subject: [PATCH] Introduce helper method for translating public locale names --- .../pageflow/admin/entry_translations_helper.rb | 7 +++---- app/helpers/pageflow/admin/locales_helper.rb | 10 +++++++--- .../entry_json_seed/_entry_translations.json.jbuilder | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/helpers/pageflow/admin/entry_translations_helper.rb b/app/helpers/pageflow/admin/entry_translations_helper.rb index cb619ce68e..b82c75d4e1 100644 --- a/app/helpers/pageflow/admin/entry_translations_helper.rb +++ b/app/helpers/pageflow/admin/entry_translations_helper.rb @@ -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:) diff --git a/app/helpers/pageflow/admin/locales_helper.rb b/app/helpers/pageflow/admin/locales_helper.rb index 0c9456faa9..ab6999e33f 100644 --- a/app/helpers/pageflow/admin/locales_helper.rb +++ b/app/helpers/pageflow/admin/locales_helper.rb @@ -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 diff --git a/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry_translations.json.jbuilder b/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry_translations.json.jbuilder index 1aada2b727..3d706d6ac4 100644 --- a/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry_translations.json.jbuilder +++ b/entry_types/scrolled/app/views/pageflow_scrolled/entry_json_seed/_entry_translations.json.jbuilder @@ -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)