Skip to content

Commit

Permalink
Don't override the admin locale session key
Browse files Browse the repository at this point in the history
The previous implementation was writing on the session key if the
requested locale was empty and the session key was set.
  • Loading branch information
elia committed Aug 3, 2023
1 parent 12d999c commit 9ce3bc6
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions admin/app/controllers/solidus_admin/controller_helpers/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,27 @@ module SolidusAdmin::ControllerHelpers::Locale

included do
before_action :set_locale
before_action :update_user_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]
def update_user_locale
requested_locale = params[:switch_to_locale] or return

if requested_locale.to_sym != user_locale
session[set_user_language_locale_key] = requested_locale

Check warning on line 18 in admin/app/controllers/solidus_admin/controller_helpers/locale.rb

View check run for this annotation

Codecov / codecov/patch

admin/app/controllers/solidus_admin/controller_helpers/locale.rb#L17-L18

Added lines #L17 - L18 were not covered by tests

flash[:notice] = t('spree.locale_changed')
redirect_to url_for(request.params.except(:switch_to_locale))

Check warning on line 21 in admin/app/controllers/solidus_admin/controller_helpers/locale.rb

View check run for this annotation

Codecov / codecov/patch

admin/app/controllers/solidus_admin/controller_helpers/locale.rb#L20-L21

Added lines #L20 - L21 were not covered by tests
end
end

I18n.locale = session[set_user_language_locale_key] ? session[set_user_language_locale_key].to_sym : I18n.default_locale
def user_locale
session[set_user_language_locale_key] || I18n.default_locale
end

def set_locale
I18n.locale = user_locale
end
end

0 comments on commit 9ce3bc6

Please sign in to comment.