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,7 +24,9 @@ class ApplicationController < ActionController::Base | ||
24 | # Be sure to include AuthenticationSystem in Application Controller instead | 24 | # Be sure to include AuthenticationSystem in Application Controller instead |
25 | include AuthenticatedSystem | 25 | include AuthenticatedSystem |
26 | include PermissionCheck | 26 | include PermissionCheck |
27 | + | ||
27 | init_gettext 'noosfero' | 28 | init_gettext 'noosfero' |
29 | + before_init_gettext :set_locale | ||
28 | 30 | ||
29 | include NeedsProfile | 31 | include NeedsProfile |
30 | 32 | ||
@@ -60,4 +62,16 @@ class ApplicationController < ActionController::Base | @@ -60,4 +62,16 @@ class ApplicationController < ActionController::Base | ||
60 | current_user.person if logged_in? | 62 | current_user.person if logged_in? |
61 | end | 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 | end | 77 | end |
app/helpers/language_helper.rb
app/views/layouts/application.rhtml
@@ -117,8 +117,11 @@ | @@ -117,8 +117,11 @@ | ||
117 | </div><!-- id="wrap" --> | 117 | </div><!-- id="wrap" --> |
118 | 118 | ||
119 | <div id="footer"> | 119 | <div id="footer"> |
120 | + <div id='language-chooser'> | ||
121 | + <%= render :file => 'shared/language_chooser' %> | ||
122 | + </div> | ||
123 | + | ||
120 | <!-- <a name='footer'/></a> --> | 124 | <!-- <a name='footer'/></a> --> |
121 | - <%= localist_menu %> | ||
122 | <%= footer %> | 125 | <%= footer %> |
123 | </div><!-- id="footer" --> | 126 | </div><!-- id="footer" --> |
124 | 127 |
config/environment.rb
@@ -69,9 +69,10 @@ end | @@ -69,9 +69,10 @@ end | ||
69 | 69 | ||
70 | 70 | ||
71 | require 'gettext/rails' | 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 | Tag.hierarchical = true | 77 | Tag.hierarchical = true |
77 | 78 |
lib/noosfero.rb
@@ -16,6 +16,10 @@ module Noosfero | @@ -16,6 +16,10 @@ module Noosfero | ||
16 | Regexp.new(items.blank? ? '' : ('(' + items + ')')) | 16 | Regexp.new(items.blank? ? '' : ('(' + items + ')')) |
17 | end | 17 | end |
18 | 18 | ||
19 | + class << self | ||
20 | + attr_accessor :locales | ||
21 | + end | ||
22 | + | ||
19 | private | 23 | private |
20 | 24 | ||
21 | def self.controllers_in_directory(dir) | 25 | def self.controllers_in_directory(dir) |
public/stylesheets/common.css
@@ -429,3 +429,7 @@ body.category4 #content h4, body.category4 #content h5, body.category4 #content | @@ -429,3 +429,7 @@ body.category4 #content h4, body.category4 #content h5, body.category4 #content | ||
429 | color: #AAA; | 429 | color: #AAA; |
430 | } | 430 | } |
431 | 431 | ||
432 | +#language-chooser { | ||
433 | + margin-bottom: 1em; | ||
434 | + text-align: center; | ||
435 | +} |
test/functional/application_controller_test.rb
@@ -118,4 +118,5 @@ class ApplicationControllerTest < Test::Unit::TestCase | @@ -118,4 +118,5 @@ class ApplicationControllerTest < Test::Unit::TestCase | ||
118 | get :index | 118 | get :index |
119 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } | 119 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } |
120 | end | 120 | end |
121 | + | ||
121 | end | 122 | end |
test/functional/search_controller_test.rb
@@ -22,7 +22,7 @@ class SearchControllerTest < Test::Unit::TestCase | @@ -22,7 +22,7 @@ class SearchControllerTest < Test::Unit::TestCase | ||
22 | end | 22 | end |
23 | 23 | ||
24 | should 'filter stop words' do | 24 | should 'filter stop words' do |
25 | - Locale.current = Locale::Object.new('pt_BR') | 25 | + GetText.locale = 'pt_BR' |
26 | get 'index', :query => 'a carne da vaca' | 26 | get 'index', :query => 'a carne da vaca' |
27 | assert_response :success | 27 | assert_response :success |
28 | assert_template 'index' | 28 | assert_template 'index' |
@@ -0,0 +1,26 @@ | @@ -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 |