-
-
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.
Extract the locale helpers to a dedicated namespace
- Loading branch information
Showing
2 changed files
with
22 additions
and
15 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
21 changes: 21 additions & 0 deletions
21
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,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 |