locale query params for session_locale
fixes CAT-330 NOTE: *the locale for a page is inferred in a weighted order. session_locale is checked just before a provided context's account locale preference and just after the user's Test Plan 1. Fire up canvas with full i18n support configured (i.e. $ RAILS_LOAD_ALL_LOCALES=true rails server) 2. Navigate to a page that supports localization while logged out such as the login screen 3. Append the following query params to the URL in the browser '?session_locale=zh' 4. Navigate to that URL and ensure the page is localized in the provided locale Change-Id: I9e94d6ecfd41e77683940272aa0988c67064b602 Reviewed-on: https://gerrit.instructure.com/39844 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Ethan Gunderson <egunderson@instructure.com> Reviewed-by: Nick Houle <nhoule@instructure.com> Product-Review: Adam Phillipps <adam@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com>
This commit is contained in:
parent
c25fbb14ac
commit
d7503ce64c
|
@ -184,17 +184,25 @@ class ApplicationController < ActionController::Base
|
|||
infer_locale :context => @context,
|
||||
:user => @current_user,
|
||||
:root_account => @domain_root_account,
|
||||
:session_locale => session[:locale],
|
||||
:accept_language => request.headers['Accept-Language']
|
||||
}
|
||||
end
|
||||
|
||||
def set_locale
|
||||
store_session_locale
|
||||
assign_localizer
|
||||
yield if block_given?
|
||||
ensure
|
||||
I18n.localizer = nil
|
||||
end
|
||||
|
||||
def store_session_locale
|
||||
return unless locale = params[:session_locale]
|
||||
supported_locales = I18n.available_locales.map(&:to_s)
|
||||
session[:locale] = locale if supported_locales.include? locale
|
||||
end
|
||||
|
||||
def init_body_classes
|
||||
@body_classes = []
|
||||
end
|
||||
|
|
|
@ -4,6 +4,7 @@ module LocaleSelection
|
|||
user = options[:user]
|
||||
root_account = options[:root_account]
|
||||
accept_language = options[:accept_language]
|
||||
session_locale = options[:session_locale]
|
||||
|
||||
# groups cheat and set the context to be the group after get_context runs
|
||||
# but before set_locale runs, but we want to do locale lookup based on the
|
||||
|
@ -16,6 +17,8 @@ module LocaleSelection
|
|||
context.locale
|
||||
elsif user && user.locale
|
||||
user.locale
|
||||
elsif session_locale
|
||||
session_locale
|
||||
elsif context && context.is_a?(Course) && context.account && (account_locale = context.account.default_locale(true))
|
||||
account_locale
|
||||
elsif context && context.is_a?(Account) && (account_locale = context.default_locale(true))
|
||||
|
|
|
@ -89,7 +89,7 @@ describe LocaleSelection do
|
|||
|
||||
context "locale matching" do
|
||||
before do
|
||||
I18n.stubs(:available_locales).returns([:en, :it, :es, :fr, :de, :pt])
|
||||
I18n.stubs(:available_locales).returns([:en, :it, :es, :fr, :de, :pt, :zh])
|
||||
@root_account = Account.create
|
||||
@account = Account.create(:parent_account => @root_account)
|
||||
user
|
||||
|
@ -164,5 +164,14 @@ describe LocaleSelection do
|
|||
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => account_gr).should eql('fr')
|
||||
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :user => @user, :context => course_gr).should eql('es')
|
||||
end
|
||||
|
||||
it "should infer the locale from the session" do
|
||||
@root_account.update_attribute(:default_locale, 'es')
|
||||
@account.update_attribute(:default_locale, 'fr')
|
||||
@user.update_attribute(:locale, 'de')
|
||||
|
||||
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :context => @account, :session_locale => 'zh').should eql('zh')
|
||||
ls.infer_locale(:accept_language => "it", :root_account => @root_account, :context => @account, :user => @user, :session_locale => 'zh').should eql('de')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue