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 | 71 | end |
72 | 72 | |
73 | 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 | 90 | init_gettext 'noosfero' |
76 | 91 | |
77 | 92 | include NeedsProfile |
... | ... | @@ -123,12 +138,6 @@ class ApplicationController < ActionController::Base |
123 | 138 | current_user.person if logged_in? |
124 | 139 | end |
125 | 140 | |
126 | - def maybe_save_locale | |
127 | - if params[:lang] | |
128 | - cookies[:lang] = params[:lang] | |
129 | - end | |
130 | - end | |
131 | - | |
132 | 141 | def load_category |
133 | 142 | unless params[:category_path].blank? |
134 | 143 | path = params[:category_path].join('/') | ... | ... |
app/helpers/language_helper.rb
1 | 1 | module LanguageHelper |
2 | 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 | 6 | else |
7 | - Noosfero.default_locale | |
7 | + Noosfero.default_locale || 'en' | |
8 | 8 | end |
9 | 9 | end |
10 | 10 | ... | ... |
config/environment.rb
features/internationalization.feature
... | ... | @@ -7,6 +7,12 @@ Feature: internationalization |
7 | 7 | When I go to the homepage |
8 | 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 | 16 | Scenario: detecting language from browser |
11 | 17 | Given my browser prefers Portuguese |
12 | 18 | When I go to the homepage | ... | ... |
features/step_definitions/internationalization_steps.rb
... | ... | @@ -21,6 +21,15 @@ def language_to_code(name) |
21 | 21 | language_to_header(name) |
22 | 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 | 33 | Given /^a user accessed in (.*) before$/ do |lang| |
25 | 34 | session = Webrat::Session.new(Webrat.adapter_class.new(self)) |
26 | 35 | session.extend(Webrat::Matchers) | ... | ... |