-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5303 from solidusio/elia/admin/locale-fix
[Admin] Fix user locale handling in SolidusAdmin
- Loading branch information
Showing
4 changed files
with
37 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
admin/app/controllers/solidus_admin/auth.rb → .../solidus_admin/controller_helpers/auth.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
admin/app/controllers/solidus_admin/controller_helpers/locale.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
module SolidusAdmin::ControllerHelpers::Locale | ||
extend ActiveSupport::Concern | ||
include Spree::Admin::SetsUserLanguageLocaleKey | ||
|
||
included do | ||
before_action :set_locale | ||
before_action :update_user_locale | ||
end | ||
|
||
private | ||
|
||
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 | ||
|
||
flash[:notice] = t('spree.locale_changed') | ||
redirect_to url_for(request.params.except(:switch_to_locale)) | ||
end | ||
end | ||
|
||
def user_locale | ||
session[set_user_language_locale_key] || I18n.default_locale | ||
end | ||
|
||
def set_locale | ||
I18n.locale = user_locale | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters