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,10 +64,15 @@ class ApplicationController < ActionController::Base | ||
64 | 64 | ||
65 | def force_language | 65 | def force_language |
66 | lang = params[:lang] | 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 | cookies[:lang] = lang | 72 | cookies[:lang] = lang |
69 | - GetText.locale = lang | ||
70 | end | 73 | end |
74 | + | ||
75 | + set_locale lang unless lang.blank? | ||
71 | end | 76 | end |
72 | 77 | ||
73 | end | 78 | end |
test/integration/locale_setting_test.rb
@@ -7,6 +7,13 @@ class LocaleSettingTest < ActionController::IntegrationTest | @@ -7,6 +7,13 @@ class LocaleSettingTest < ActionController::IntegrationTest | ||
7 | GetText.locale = nil | 7 | GetText.locale = nil |
8 | end | 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 | should 'detect locale from the browser' do | 17 | should 'detect locale from the browser' do |
11 | 18 | ||
12 | # user has pt_BR | 19 | # user has pt_BR |