Commit 1df215c3c54d7583bc7367de33cade041c791f0d
1 parent
8245496f
Exists in
master
and in
29 other branches
ActionItem830: forcing a default locale
Showing
5 changed files
with
36 additions
and
12 deletions
Show diff stats
app/controllers/application.rb
@@ -71,7 +71,22 @@ class ApplicationController < ActionController::Base | @@ -71,7 +71,22 @@ class ApplicationController < ActionController::Base | ||
71 | end | 71 | end |
72 | 72 | ||
73 | include GetText | 73 | include GetText |
74 | - before_init_gettext :maybe_save_locale | 74 | + before_init_gettext :maybe_save_locale, :default_locale |
75 | + def maybe_save_locale | ||
76 | + if params[:lang] | ||
77 | + cookies[:lang] = params[:lang] | ||
78 | + end | ||
79 | + end | ||
80 | + def default_locale | ||
81 | + if Noosfero.default_locale | ||
82 | + if cookies[:lang].blank? | ||
83 | + set_locale Noosfero.default_locale | ||
84 | + else | ||
85 | + set_locale cookies[:lang] | ||
86 | + end | ||
87 | + end | ||
88 | + end | ||
89 | + protected :maybe_save_locale, :default_locale | ||
75 | init_gettext 'noosfero' | 90 | init_gettext 'noosfero' |
76 | 91 | ||
77 | include NeedsProfile | 92 | include NeedsProfile |
@@ -123,12 +138,6 @@ class ApplicationController < ActionController::Base | @@ -123,12 +138,6 @@ class ApplicationController < ActionController::Base | ||
123 | current_user.person if logged_in? | 138 | current_user.person if logged_in? |
124 | end | 139 | end |
125 | 140 | ||
126 | - def maybe_save_locale | ||
127 | - if params[:lang] | ||
128 | - cookies[:lang] = params[:lang] | ||
129 | - end | ||
130 | - end | ||
131 | - | ||
132 | def load_category | 141 | def load_category |
133 | unless params[:category_path].blank? | 142 | unless params[:category_path].blank? |
134 | path = params[:category_path].join('/') | 143 | path = params[:category_path].join('/') |
app/helpers/language_helper.rb
1 | module LanguageHelper | 1 | module LanguageHelper |
2 | def language | 2 | def language |
3 | - if Noosfero.available_locales.include?(GetText.locale.to_s) || | ||
4 | - Noosfero.available_locales.include?(GetText.locale.language) | ||
5 | - GetText.locale.language | 3 | + if Noosfero.available_locales.include?(locale.to_s) || |
4 | + Noosfero.available_locales.include?(locale.language) | ||
5 | + locale.language | ||
6 | else | 6 | else |
7 | - Noosfero.default_locale | 7 | + Noosfero.default_locale || 'en' |
8 | end | 8 | end |
9 | end | 9 | end |
10 | 10 |
config/environment.rb
@@ -119,7 +119,7 @@ Noosfero.locales = { | @@ -119,7 +119,7 @@ Noosfero.locales = { | ||
119 | 'hy' => 'հայերեն լեզու', | 119 | 'hy' => 'հայերեն լեզու', |
120 | } | 120 | } |
121 | # if you want to override this, do it in config/local.rb ! | 121 | # if you want to override this, do it in config/local.rb ! |
122 | -Noosfero.default_locale = 'en' | 122 | +Noosfero.default_locale = nil |
123 | 123 | ||
124 | Tag.hierarchical = true | 124 | Tag.hierarchical = true |
125 | 125 |
features/internationalization.feature
@@ -7,6 +7,12 @@ Feature: internationalization | @@ -7,6 +7,12 @@ Feature: internationalization | ||
7 | When I go to the homepage | 7 | When I go to the homepage |
8 | Then the site should be in English | 8 | Then the site should be in English |
9 | 9 | ||
10 | + @default_locale_config | ||
11 | + Scenario: different default locale configured locally | ||
12 | + Given Noosfero is configured to use Portuguese as default | ||
13 | + When I go to the homepage | ||
14 | + Then the site should be in Portuguese | ||
15 | + | ||
10 | Scenario: detecting language from browser | 16 | Scenario: detecting language from browser |
11 | Given my browser prefers Portuguese | 17 | Given my browser prefers Portuguese |
12 | When I go to the homepage | 18 | When I go to the homepage |
features/step_definitions/internationalization_steps.rb
@@ -21,6 +21,15 @@ def language_to_code(name) | @@ -21,6 +21,15 @@ def language_to_code(name) | ||
21 | language_to_header(name) | 21 | language_to_header(name) |
22 | end | 22 | end |
23 | 23 | ||
24 | +Given /^Noosfero is configured to use (.+) as default$/ do |lang| | ||
25 | + Noosfero.default_locale = language_to_code(lang) | ||
26 | +end | ||
27 | + | ||
28 | +After('@default_locale_config') do | ||
29 | + Noosfero.default_locale = nil | ||
30 | + GetText.locale = nil | ||
31 | +end | ||
32 | + | ||
24 | Given /^a user accessed in (.*) before$/ do |lang| | 33 | Given /^a user accessed in (.*) before$/ do |lang| |
25 | session = Webrat::Session.new(Webrat.adapter_class.new(self)) | 34 | session = Webrat::Session.new(Webrat.adapter_class.new(self)) |
26 | session.extend(Webrat::Matchers) | 35 | session.extend(Webrat::Matchers) |