From 64ec5b8529cc5ddf689b4d9b606520c8dad1f306 Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Wed, 9 May 2012 19:53:23 +0000 Subject: [PATCH] Fix browser language detection --- app/controllers/application_controller.rb | 3 ++- test/functional/application_controller_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1fe59db..1f30fc1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -42,7 +42,8 @@ class ApplicationController < ActionController::Base def set_locale FastGettext.available_locales = Noosfero.available_locales FastGettext.default_locale = Noosfero.default_locale - I18n.locale = FastGettext.locale = (params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') + FastGettext.locale = (params[:lang] || session[:lang] || Noosfero.default_locale || request.env['HTTP_ACCEPT_LANGUAGE'] || 'en') + I18n.locale = FastGettext.locale if params[:lang] session[:lang] = params[:lang] end diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index b1cc3c7..776ffd0 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -334,6 +334,12 @@ class ApplicationControllerTest < ActionController::TestCase assert_tag :html, :attributes => { :lang => 'es' } end + should 'set Rails locale correctly' do + @request.env['HTTP_ACCEPT_LANGUAGE'] = 'pt-BR,pt;q=0.8,en;q=0.6,en-US;q=0.4' + get :index + assert_equal 'pt', I18n.locale.to_s + end + should 'include stylesheets supplied by plugins' do class Plugin1 < Noosfero::Plugin def stylesheet? -- libgit2 0.21.2