Extract choose_locale method, similar to CodeHarbor
This commit is contained in:
@ -158,9 +158,29 @@ class ApplicationController < ActionController::Base
|
|||||||
response.headers['X-Content-Type-Options'] = 'nosniff'
|
response.headers['X-Content-Type-Options'] = 'nosniff'
|
||||||
end
|
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(&)
|
def switch_locale(&)
|
||||||
session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale])
|
locale = choose_locale
|
||||||
locale = session[:locale] || http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale
|
session[:locale] = locale
|
||||||
Sentry.set_extras(locale:)
|
Sentry.set_extras(locale:)
|
||||||
I18n.with_locale(locale, &)
|
I18n.with_locale(locale, &)
|
||||||
end
|
end
|
||||||
|
Reference in New Issue
Block a user