-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix : set_user_language not overriden in spree_auth_devise_controller
- Loading branch information
Showing
5 changed files
with
43 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
Spree::StoreController.class_eval do | ||
private | ||
# could not decorate Spree::Core::ControllerHelpers::Common#set_user_locale | ||
# so manualy override this method here by including ControllerHelperLocale | ||
|
||
# Internal : Set user I18n.locale | ||
# | ||
# override spree_core set_user_language | ||
# initialize user language : | ||
# params[:locale] is explicitly given by routing-filter /:locale | ||
# or the session[:locale] set by Spree::LocaleController#set | ||
# or I18n.locale set by rack-locale for example | ||
# or Spree::Config[:default_locale] | ||
# or Rails.application.config.i18n.default_locale | ||
Spree::StoreController.class_eval do | ||
include SpreeMultiLingual::ControllerHelperLocale | ||
end | ||
|
||
def set_user_language | ||
locale = params[:locale] || session[:locale] || I18n.locale || Rails.application.config.i18n.default_locale | ||
locale = I18n.default_locale unless locale && I18n.available_locales.include?(locale.to_sym) | ||
I18n.locale = locale.to_sym | ||
end | ||
# spree_devise_auth_devise controllers | ||
%w{Spree::UserRegistrationsController Spree::UserPasswordsController Spree::UserSessionsController Spree::UsersController}.each do |klass| | ||
klass.class_eval do | ||
include SpreeMultiLingual::ControllerHelperLocale | ||
end if klass = klass.safe_constantize | ||
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
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,26 @@ | ||
module SpreeMultiLingual::ControllerHelperLocale | ||
extend ActiveSupport::Concern | ||
|
||
included do |base| | ||
# only way to make sure that set_user_language included by spree_auth_devise controller is overriden correctly | ||
base.class_eval do | ||
private | ||
|
||
# Internal : Set user I18n.locale | ||
# | ||
# override spree_core set_user_language | ||
# initialize user language : | ||
# params[:locale] is explicitly given by routing-filter /:locale | ||
# or the session[:locale] set by Spree::LocaleController#set | ||
# or I18n.locale set by rack-locale for example | ||
# or Spree::Config[:default_locale] | ||
# or Rails.application.config.i18n.default_locale | ||
def set_user_language | ||
locale = params[:locale] || session[:locale] || I18n.locale || Rails.application.config.i18n.default_locale | ||
locale = I18n.default_locale unless locale && I18n.available_locales.include?(locale.to_sym) | ||
I18n.locale = locale.to_sym | ||
end | ||
end | ||
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
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