I18n: Automatically choose locale through HTTP header
This commit is contained in:
1
Gemfile
1
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'
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user