Skip to content

Commit

Permalink
fix : set_user_language not overriden in spree_auth_devise_controller
Browse files Browse the repository at this point in the history
  • Loading branch information
sbounmy committed Oct 19, 2013
1 parent 588dd36 commit f5c42cf
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 21 deletions.
26 changes: 10 additions & 16 deletions app/controllers/store_controller_decorator.rb
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
8 changes: 5 additions & 3 deletions app/overrides/taxonomy_add_multi_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
:partial => "spree/admin/taxonomies/multi_language_links")

Deface::Override.new(
:virtual_path => "spree/admin/taxons/edit",
:insert_before => '[data-hook="buttons"]',
:text => '<%= render "spree/admin/taxons/multi_scripts", :object => @taxon -%>',
:virtual_path => "spree/admin/taxons/_form",
:insert_top => '[data-hook="admin_inside_taxon_form"]',
:text => ' <div class="alpha twelve columns">
<%= render "spree/admin/taxons/multi_scripts", :object => @taxon -%>
</div>',
:name => "taxon_add_language_dropdown")
26 changes: 26 additions & 0 deletions lib/spree_multi_lingual/controller_helper_locale.rb
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
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

require 'rspec/rails'
require 'ffaker'
# require 'debugger'
require 'debugger'

# Requires supporting ruby files with custom matchers and macros, etc,
# in spec/support/ and its subdirectories.
Expand Down
2 changes: 1 addition & 1 deletion spree_multi_lingual.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Gem::Specification.new do |s|
s.add_development_dependency 'email_spec', '~> 1.2.1'
s.add_development_dependency 'selenium-webdriver', '2.35.1'
# Seems Spree doesn't require it correctly or there is a problem with extensions maybe? Still, it is needed to work with the dummy app!
# s.add_development_dependency 'debugger'
s.add_development_dependency 'debugger'
s.add_development_dependency 'sass-rails'
end

0 comments on commit f5c42cf

Please sign in to comment.