Skip to content

Commit

Permalink
don't auto select as local language a disabled language (e.g DE)
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Sep 5, 2024
1 parent bc06fff commit 138c268
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# Likewise, all the methods added will be available for all controllers.

class ApplicationController < ActionController::Base
include InternationalisationHelper
include InternationalisationHelper, MultiLanguagesHelper

before_action :set_locale

Expand All @@ -26,6 +26,9 @@ def set_locale
I18n.locale = cookies[:locale] || detect_locale
cookies.permanent[:locale] = I18n.locale if cookies[:locale].nil?
logger.debug "* Locale set to '#{I18n.locale}'"

I18n.locale = portal_lang if portal_language_enabled?(I18n.locale)

session[:locale] = I18n.locale
end

Expand Down
5 changes: 3 additions & 2 deletions app/controllers/language_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class LanguageController < ApplicationController

include MultiLanguagesHelper
# set locale to the language selected by the user
def set_locale_language
language = params[:language].strip.downcase.to_sym
supported_languages = I18n.available_locales

if language
if language && portal_language_enabled?(language)
if supported_languages.include?(language)
cookies.permanent[:locale] = language
else
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/multi_languages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ def portal_languages
}
end

def portal_language_enabled?(lang)
portal_languages.reject { |_k, x| x[:disabled] }.keys.include?(lang)
end

def portal_language_selector
languages = portal_languages
selected_language = portal_lang
Expand Down

0 comments on commit 138c268

Please sign in to comment.