Commit 86c3b33505fe7fde52fe098f7a1d4063188376e6
1 parent
faedec80
Exists in
master
and in
29 other branches
ActionItem181: adding the ability to define a default locale
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1451 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
2 changed files
with
14 additions
and
2 deletions
Show diff stats
app/controllers/application.rb
... | ... | @@ -64,10 +64,15 @@ class ApplicationController < ActionController::Base |
64 | 64 | |
65 | 65 | def force_language |
66 | 66 | lang = params[:lang] |
67 | - unless lang.blank? | |
67 | + if lang.blank? | |
68 | + # no language forced, get language from cookie | |
69 | + lang = cookies[:lang] || Noosfero.default_locale | |
70 | + else | |
71 | + # save forced language in the cookie | |
68 | 72 | cookies[:lang] = lang |
69 | - GetText.locale = lang | |
70 | 73 | end |
74 | + | |
75 | + set_locale lang unless lang.blank? | |
71 | 76 | end |
72 | 77 | |
73 | 78 | end | ... | ... |
test/integration/locale_setting_test.rb
... | ... | @@ -7,6 +7,13 @@ class LocaleSettingTest < ActionController::IntegrationTest |
7 | 7 | GetText.locale = nil |
8 | 8 | end |
9 | 9 | |
10 | + should 'be able to set a default language' do | |
11 | + Noosfero.expects(:default_locale).returns('pt_BR').at_least_once | |
12 | + | |
13 | + get '/' | |
14 | + assert_equal 'pt_BR', GetText.locale.to_s | |
15 | + end | |
16 | + | |
10 | 17 | should 'detect locale from the browser' do |
11 | 18 | |
12 | 19 | # user has pt_BR | ... | ... |