Skip to content

Commit

Permalink
Accept switch_to_locale param in LocaleController
Browse files Browse the repository at this point in the history
Previously we accepted only the :locale param in LocaleController#set.

solidus_i18n, however, only accepts the :switch_to_locale param. This is
because solidus_i18n uses the :locale param as part of it's path
(ex. /en/products).

For better compatiblity with solidus_i18n, and so that we can merge most
of it's functionality, we should accept either param here (and probably
should prefer :switch_to_locale).
  • Loading branch information
jhawthorn committed Mar 29, 2018
1 parent cec9040 commit 0db484d
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions frontend/app/controllers/spree/locale_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
module Spree
class LocaleController < Spree::StoreController
def set
if params[:locale] && I18n.available_locales.map(&:to_s).include?(params[:locale])
session[:locale] = I18n.locale = params[:locale]
available_locales = Spree.i18n_available_locales
requested_locale = params[:switch_to_locale] || params[:locale]

if requested_locale && available_locales.map(&:to_s).include?(requested_locale)
session[:locale] = requested_locale
I18n.locale = requested_locale
flash.notice = t('spree.locale_changed')
else
flash[:error] = t('spree.locale_not_changed')
Expand Down

0 comments on commit 0db484d

Please sign in to comment.