Commit 64ec5b8529cc5ddf689b4d9b606520c8dad1f306
Committed by
Daniela Feitosa
1 parent
1b0b8860
Exists in
master
and in
29 other branches
Fix browser language detection
FastGettext.locale= returns its argument instead of returning the locale that was actually detected. (ActionItem2297)
Showing
2 changed files
with
8 additions
and
1 deletions
Show diff stats
app/controllers/application_controller.rb
@@ -42,7 +42,8 @@ class ApplicationController < ActionController::Base | @@ -42,7 +42,8 @@ class ApplicationController < ActionController::Base | ||
42 | def set_locale | 42 | def set_locale |
43 | FastGettext.available_locales = Noosfero.available_locales | 43 | FastGettext.available_locales = Noosfero.available_locales |
44 | FastGettext.default_locale = Noosfero.default_locale | 44 | FastGettext.default_locale = Noosfero.default_locale |
45 | - I18n.locale = FastGettext.locale = (params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') | 45 | + FastGettext.locale = (params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') |
46 | + I18n.locale = FastGettext.locale | ||
46 | if params[:lang] | 47 | if params[:lang] |
47 | session[:lang] = params[:lang] | 48 | session[:lang] = params[:lang] |
48 | end | 49 | end |
test/functional/application_controller_test.rb
@@ -334,6 +334,12 @@ class ApplicationControllerTest < ActionController::TestCase | @@ -334,6 +334,12 @@ class ApplicationControllerTest < ActionController::TestCase | ||
334 | assert_tag :html, :attributes => { :lang => 'es' } | 334 | assert_tag :html, :attributes => { :lang => 'es' } |
335 | end | 335 | end |
336 | 336 | ||
337 | + should 'set Rails locale correctly' do | ||
338 | + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'pt-BR,pt;q=0.8,en;q=0.6,en-US;q=0.4' | ||
339 | + get :index | ||
340 | + assert_equal 'pt', I18n.locale.to_s | ||
341 | + end | ||
342 | + | ||
337 | should 'include stylesheets supplied by plugins' do | 343 | should 'include stylesheets supplied by plugins' do |
338 | class Plugin1 < Noosfero::Plugin | 344 | class Plugin1 < Noosfero::Plugin |
339 | def stylesheet? | 345 | def stylesheet? |