diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index a9fc33ab..a1b91309 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -158,9 +158,29 @@ class ApplicationController < ActionController::Base response.headers['X-Content-Type-Options'] = 'nosniff' end + def sanitized_lti_locale_param + sanitize_locale(params[:custom_locale]) + end + + def sanitized_locale_param + sanitize_locale(params[:locale]) + end + + def sanitized_session_locale + sanitize_locale(session[:locale]) + end + + def choose_locale + sanitized_lti_locale_param || + sanitized_locale_param || + sanitized_session_locale || + http_accept_language.compatible_language_from(I18n.available_locales) || + I18n.default_locale + end + def switch_locale(&) - session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale]) - locale = session[:locale] || http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale + locale = choose_locale + session[:locale] = locale Sentry.set_extras(locale:) I18n.with_locale(locale, &) end