From 12d999cd9b1f8caf41b13dee14bfe91aea66b67b Mon Sep 17 00:00:00 2001 From: Elia Schito Date: Thu, 3 Aug 2023 18:19:50 +0200 Subject: [PATCH] Extract the locale helpers to a dedicated namespace --- .../solidus_admin/base_controller.rb | 16 +------------- .../controller_helpers/locale.rb | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+), 15 deletions(-) create mode 100644 admin/app/controllers/solidus_admin/controller_helpers/locale.rb diff --git a/admin/app/controllers/solidus_admin/base_controller.rb b/admin/app/controllers/solidus_admin/base_controller.rb index 0b5f048ec09..f76f060b4d9 100644 --- a/admin/app/controllers/solidus_admin/base_controller.rb +++ b/admin/app/controllers/solidus_admin/base_controller.rb @@ -6,28 +6,14 @@ module SolidusAdmin class BaseController < ApplicationController include ActiveStorage::SetCurrent include Spree::Core::ControllerHelpers::Store - include Spree::Admin::SetsUserLanguageLocaleKey include GearedPagination::Controller include SolidusAdmin::ControllerHelpers::Auth + include SolidusAdmin::ControllerHelpers::Locale include SolidusAdmin::AuthAdapters::Backend if defined?(Spree::Backend) - - before_action :set_locale - layout 'solidus_admin/application' helper 'solidus_admin/container' helper 'solidus_admin/layout' - - private - - def set_locale - if params[:switch_to_locale].to_s != session[set_user_language_locale_key].to_s - session[set_user_language_locale_key] = params[:switch_to_locale] - flash[:notice] = t('spree.locale_changed') - end - - I18n.locale = session[set_user_language_locale_key] ? session[set_user_language_locale_key].to_sym : I18n.default_locale - end end end diff --git a/admin/app/controllers/solidus_admin/controller_helpers/locale.rb b/admin/app/controllers/solidus_admin/controller_helpers/locale.rb new file mode 100644 index 00000000000..b99b59db01b --- /dev/null +++ b/admin/app/controllers/solidus_admin/controller_helpers/locale.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +module SolidusAdmin::ControllerHelpers::Locale + extend ActiveSupport::Concern + include Spree::Admin::SetsUserLanguageLocaleKey + + included do + before_action :set_locale + end + + private + + def set_locale + if params[:switch_to_locale].to_s != session[set_user_language_locale_key].to_s + session[set_user_language_locale_key] = params[:switch_to_locale] + flash[:notice] = t('spree.locale_changed') + end + + I18n.locale = session[set_user_language_locale_key] ? session[set_user_language_locale_key].to_sym : I18n.default_locale + end +end