Commit 242b74319bc15585ca32cd6f252107118f05c5c0
1 parent
15102f5f
Exists in
master
and in
29 other branches
ActionItem137: displaying a list of languages to switch languages instead of the…
… flags (like e.g. gnu.org or debian.org) git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1299 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
10 changed files
with
66 additions
and
10 deletions
Show diff stats
app/controllers/application.rb
... | ... | @@ -24,7 +24,9 @@ class ApplicationController < ActionController::Base |
24 | 24 | # Be sure to include AuthenticationSystem in Application Controller instead |
25 | 25 | include AuthenticatedSystem |
26 | 26 | include PermissionCheck |
27 | + | |
27 | 28 | init_gettext 'noosfero' |
29 | + before_init_gettext :set_locale | |
28 | 30 | |
29 | 31 | include NeedsProfile |
30 | 32 | |
... | ... | @@ -60,4 +62,16 @@ class ApplicationController < ActionController::Base |
60 | 62 | current_user.person if logged_in? |
61 | 63 | end |
62 | 64 | |
65 | + def set_locale | |
66 | + locale = cookies[:locale] | |
67 | + unless params[:locale].blank? | |
68 | + locale = params[:locale] | |
69 | + end | |
70 | + | |
71 | + if locale | |
72 | + cookies[:locale] = locale | |
73 | + GetText.locale = locale | |
74 | + end | |
75 | + end | |
76 | + | |
63 | 77 | end | ... | ... |
app/helpers/language_helper.rb
app/views/layouts/application.rhtml
... | ... | @@ -117,8 +117,11 @@ |
117 | 117 | </div><!-- id="wrap" --> |
118 | 118 | |
119 | 119 | <div id="footer"> |
120 | + <div id='language-chooser'> | |
121 | + <%= render :file => 'shared/language_chooser' %> | |
122 | + </div> | |
123 | + | |
120 | 124 | <!-- <a name='footer'/></a> --> |
121 | - <%= localist_menu %> | |
122 | 125 | <%= footer %> |
123 | 126 | </div><!-- id="footer" --> |
124 | 127 | ... | ... |
config/environment.rb
... | ... | @@ -69,9 +69,10 @@ end |
69 | 69 | |
70 | 70 | |
71 | 71 | require 'gettext/rails' |
72 | -Localist.supported_locales = %w[en-US pt-BR] | |
73 | -Localist.default_locale = "pt-BR" | |
74 | -Localist.callback = lambda { |l| GetText.locale= l } | |
72 | +Noosfero.locales = { | |
73 | + 'en' => 'English', | |
74 | + 'pt_BR' => 'Português Brasileiro', | |
75 | +} | |
75 | 76 | |
76 | 77 | Tag.hierarchical = true |
77 | 78 | ... | ... |
lib/noosfero.rb
public/stylesheets/common.css
test/functional/application_controller_test.rb
test/functional/search_controller_test.rb
... | ... | @@ -22,7 +22,7 @@ class SearchControllerTest < Test::Unit::TestCase |
22 | 22 | end |
23 | 23 | |
24 | 24 | should 'filter stop words' do |
25 | - Locale.current = Locale::Object.new('pt_BR') | |
25 | + GetText.locale = 'pt_BR' | |
26 | 26 | get 'index', :query => 'a carne da vaca' |
27 | 27 | assert_response :success |
28 | 28 | assert_template 'index' | ... | ... |
... | ... | @@ -0,0 +1,26 @@ |
1 | +require "#{File.dirname(__FILE__)}/../test_helper" | |
2 | + | |
3 | +class LocaleSettingTest < ActionController::IntegrationTest | |
4 | + | |
5 | + should 'set locale properly' do | |
6 | + | |
7 | + # set locale to pt_BR | |
8 | + get '/', :locale => 'pt_BR' | |
9 | + assert_equal 'pt_BR', GetText.locale.to_s | |
10 | + | |
11 | + # locale is kept | |
12 | + get '/' | |
13 | + assert_equal 'pt_BR', GetText.locale.to_s | |
14 | + | |
15 | + # changing back | |
16 | + get '/', :locale => 'en' | |
17 | + assert_equal 'en', GetText.locale.to_s | |
18 | + | |
19 | + # locale is kept again | |
20 | + get '/' | |
21 | + assert_equal 'en', GetText.locale.to_s | |
22 | + | |
23 | + end | |
24 | + | |
25 | + | |
26 | +end | ... | ... |