diff --git a/Gemfile b/Gemfile index 5c06f5cd..777148c8 100644 --- a/Gemfile +++ b/Gemfile @@ -14,6 +14,7 @@ gem 'faraday-net_http_persistent' gem 'faye-websocket' gem 'forgery' gem 'highline' +gem 'http_accept_language' gem 'i18n-js' gem 'ims-lti', '< 2.0.0' # Version 2 implements LTI 2.0, which is deprecated. Hence, we stay with version 1. gem 'jbuilder' diff --git a/Gemfile.lock b/Gemfile.lock index e7ee337e..545ace11 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -181,6 +181,7 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + http_accept_language (2.1.1) i18n (1.12.0) concurrent-ruby (~> 1.0) i18n-js (4.2.0) @@ -561,6 +562,7 @@ DEPENDENCIES forgery headless highline + http_accept_language i18n-js ims-lti (< 2.0.0) jbuilder diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9902898c..a6bb9cd8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -122,7 +122,7 @@ class ApplicationController < ActionController::Base def switch_locale(&) session[:locale] = sanitize_locale(params[:custom_locale] || params[:locale] || session[:locale]) - locale = session[:locale] || I18n.default_locale + locale = session[:locale] || http_accept_language.compatible_language_from(I18n.available_locales) || I18n.default_locale Sentry.set_extras(locale:) I18n.with_locale(locale, &) end