diff --git a/app/controllers/application.rb b/app/controllers/application.rb index db163f2..673d5ba 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -64,10 +64,15 @@ class ApplicationController < ActionController::Base def force_language lang = params[:lang] - unless lang.blank? + if lang.blank? + # no language forced, get language from cookie + lang = cookies[:lang] || Noosfero.default_locale + else + # save forced language in the cookie cookies[:lang] = lang - GetText.locale = lang end + + set_locale lang unless lang.blank? end end diff --git a/test/integration/locale_setting_test.rb b/test/integration/locale_setting_test.rb index ecdd0b1..2f6e885 100644 --- a/test/integration/locale_setting_test.rb +++ b/test/integration/locale_setting_test.rb @@ -7,6 +7,13 @@ class LocaleSettingTest < ActionController::IntegrationTest GetText.locale = nil end + should 'be able to set a default language' do + Noosfero.expects(:default_locale).returns('pt_BR').at_least_once + + get '/' + assert_equal 'pt_BR', GetText.locale.to_s + end + should 'detect locale from the browser' do # user has pt_BR -- libgit2 0.21.2