mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Create a new method to change the lang of the app
- The old method (link to `?locale=#{l.to_s}`) was not functional for path that already has query params in current path (such as `/user/spree_user/password/edit?reset_password_token=`) ;
- This seems that the best way to handle this, is to create a new route, new method that effectively set the lang (not the locale actually...) and then redirect_back (ie. using the HTTP_REFERER, with a fallback to `/`)
s
This commit is contained in:
8
app/controllers/locales_controller.rb
Normal file
8
app/controllers/locales_controller.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class LocalesController < BaseController
|
||||
def show
|
||||
UserLocaleSetter.new(spree_current_user, params[:id], cookies).set_locale
|
||||
redirect_back fallback_location: main_app.root_url
|
||||
end
|
||||
end
|
||||
@@ -5,4 +5,4 @@
|
||||
%ul.dropdown
|
||||
- OpenFoodNetwork::I18nConfig.selectable_locales.each do |l|
|
||||
%li
|
||||
%a{href: "?locale=#{l.to_s}" }= t('language_name', locale: l)
|
||||
= link_to t('language_name', locale: l), main_app.locale_path(l.to_s)
|
||||
|
||||
@@ -20,6 +20,7 @@ Openfoodnetwork::Application.routes.draw do
|
||||
get "/register", to: "registration#index", as: :registration
|
||||
get "/register/auth", to: "registration#authenticate", as: :registration_auth
|
||||
post "/user/registered_email", to: "spree/users#registered_email"
|
||||
resources :locales, only: [:show]
|
||||
|
||||
# Redirects to global website
|
||||
get "/connect", to: redirect("https://openfoodnetwork.org/#{ENV['DEFAULT_COUNTRY_CODE'].andand.downcase}/connect/")
|
||||
|
||||
@@ -127,11 +127,11 @@ feature 'Multilingual', js: true do
|
||||
|
||||
find('.language-switcher').click
|
||||
within '.language-switcher .dropdown' do
|
||||
expect(page).to have_link I18n.t('language_name', locale: :en), href: '?locale=en'
|
||||
expect(page).to have_link I18n.t('language_name', locale: :en), href: '/locales/en'
|
||||
expect(page).to have_link I18n.t('language_name', locale: :es, default: 'Language Name'),
|
||||
href: '?locale=es'
|
||||
href: '/locales/es'
|
||||
|
||||
find('li a[href="?locale=es"]').click
|
||||
find('li a[href="/locales/es"]').click
|
||||
end
|
||||
|
||||
expect_menu_and_cookie_in_es
|
||||
|
||||
Reference in New Issue
Block a user