Skip to content

Commit

Permalink
Extract the locale helpers to a dedicated namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
elia committed Aug 3, 2023
1 parent 94492a2 commit 12d999c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
16 changes: 1 addition & 15 deletions admin/app/controllers/solidus_admin/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions admin/app/controllers/solidus_admin/controller_helpers/locale.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 12d999c

Please sign in to comment.