aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitmodules2
-rw-r--r--Gemfile13
-rw-r--r--Gemfile.lock14
-rw-r--r--app/controllers/general_controller.rb42
-rw-r--r--app/models/track_mailer.rb7
-rw-r--r--app/models/user.rb7
-rw-r--r--spec/controllers/public_body_controller_spec.rb14
-rw-r--r--spec/models/public_body_spec.rb2
8 files changed, 50 insertions, 51 deletions
diff --git a/.gitmodules b/.gitmodules
index 4f9ece146..42d5db56b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -1,6 +1,8 @@
[submodule "commonlib"]
path = commonlib
url = git://git.mysociety.org/commonlib
+# config/locales is a symbolic link to vendor/rails-locales/rails/locale
+# In Rails 3, this should be removed and the gem rails-i18n installed instead
[submodule "vendor/rails-locales"]
path = vendor/rails-locales
url = git://github.com/svenfuchs/rails-i18n.git
diff --git a/Gemfile b/Gemfile
index f24eb5261..2210c29a3 100644
--- a/Gemfile
+++ b/Gemfile
@@ -10,15 +10,11 @@ source :rubygems
gem 'rails', '3.0.17'
gem 'pg'
-gem 'fast_gettext', '>= 0.6.0'
gem 'fastercsv', '>=1.5.5'
-gem 'gettext_i18n_rails', '>= 0.7.1'
-gem 'gettext', '~> 2.3.3'
gem 'json', '~> 1.5.1'
gem 'mahoro'
gem 'mail', :platforms => :ruby_19
gem 'memcache-client', :require => 'memcache'
-gem 'locale', '>= 2.0.5'
gem 'net-http-local'
gem 'net-purge'
gem 'rack'
@@ -26,7 +22,6 @@ gem 'rdoc'
gem 'recaptcha', '~> 0.3.1', :require => 'recaptcha/rails'
# :require avoids "already initialized constant" warnings
gem 'rmagick', :require => 'RMagick'
-gem 'routing-filter', '~> 0.2.4'
gem 'rake', '0.9.2.2'
gem 'ruby-msg', '~> 1.5.0'
gem 'vpim'
@@ -44,6 +39,14 @@ gem 'globalize3', :git => 'git://github.com/henare/globalize3.git', :branch => '
gem 'acts_as_versioned'
gem 'dynamic_form'
+# Gems related to internationalisation
+# Also in vendor/plugins there is globalize2
+gem 'fast_gettext'
+gem 'gettext_i18n_rails'
+gem 'gettext'
+gem 'locale'
+gem 'routing-filter'
+
group :test do
gem 'fakeweb'
gem 'test-unit', '~> 1.2.3', :platforms => :ruby_19
diff --git a/Gemfile.lock b/Gemfile.lock
index b67efa846..0b2017497 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -69,7 +69,8 @@ GEM
fast_gettext (0.6.11)
fastercsv (1.5.5)
fssm (0.2.9)
- gettext (2.3.3)
+ gettext (2.3.7)
+ levenshtein
locale
gettext_i18n_rails (0.8.0)
fast_gettext (>= 0.4.8)
@@ -79,6 +80,7 @@ GEM
rake (>= 0.8, < 11.0)
i18n (0.5.0)
json (1.5.4)
+ levenshtein (0.2.2)
linecache (0.46)
rbx-require-relative (> 0.0.4)
linecache19 (0.5.12)
@@ -220,13 +222,13 @@ DEPENDENCIES
compass
dynamic_form
fakeweb
- fast_gettext (>= 0.6.0)
+ fast_gettext
fastercsv (>= 1.5.5)
- gettext (~> 2.3.3)
- gettext_i18n_rails (>= 0.7.1)
+ gettext
+ gettext_i18n_rails
globalize3!
json (~> 1.5.1)
- locale (>= 2.0.5)
+ locale
mahoro
mail
mailcatcher
@@ -241,7 +243,7 @@ DEPENDENCIES
rdoc
recaptcha (~> 0.3.1)
rmagick
- routing-filter (~> 0.2.4)
+ routing-filter
rspec-rails
ruby-debug
ruby-debug19
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index faf34aa04..003b815d3 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -19,26 +19,28 @@ class GeneralController < ApplicationController
# New, improved front page!
def frontpage
medium_cache
- # get some example searches and public bodies to display
- # either from config, or based on a (slow!) query if not set
- body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
- @locale = self.locale_from_params()
- locale_condition = 'public_body_translations.locale = ?'
- conditions = [locale_condition, @locale]
- I18n.with_locale(@locale) do
- if body_short_names.empty?
- # This is too slow
- @popular_bodies = PublicBody.visible.find(:all,
- :order => "info_requests_count desc",
- :limit => 32,
- :conditions => conditions,
- :joins => :translations
- )
- else
- conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")"
- @popular_bodies = PublicBody.find(:all,
- :conditions => conditions,
- :joins => :translations)
+ behavior_cache :tag => [session[:user_id], request.url] do
+ # get some example searches and public bodies to display
+ # either from config, or based on a (slow!) query if not set
+ body_short_names = Configuration::frontpage_publicbody_examples.split(/\s*;\s*/).map{|s| "'%s'" % s.gsub(/'/, "''") }.join(", ")
+ @locale = self.locale_from_params()
+ locale_condition = 'public_body_translations.locale = ?'
+ conditions = [locale_condition, @locale]
+ I18n.with_locale(@locale) do
+ if body_short_names.empty?
+ # This is too slow
+ @popular_bodies = PublicBody.visible.find(:all,
+ :order => "info_requests_count desc",
+ :limit => 32,
+ :conditions => conditions,
+ :joins => :translations
+ )
+ else
+ conditions[0] += " and public_bodies.url_name in (" + body_short_names + ")"
+ @popular_bodies = PublicBody.find(:all,
+ :conditions => conditions,
+ :joins => :translations)
+ end
end
end
# Get some successful requests
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 7dfa87f52..03310478a 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -91,10 +91,9 @@ class TrackMailer < ApplicationMailer
if email_about_things.size > 0
# Send the email
- previous_locale = I18n.locale
- I18n.locale = user.get_locale
- TrackMailer.deliver_event_digest(user, email_about_things)
- I18n.locale = previous_locale
+ I18n.with_locale(user.get_locale) do
+ TrackMailer.deliver_event_digest(user, email_about_things)
+ end
end
# Record that we've now sent those alerts to that user
diff --git a/app/models/user.rb b/app/models/user.rb
index 490587c39..bc04b5449 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -90,12 +90,7 @@ class User < ActiveRecord::Base
end
def get_locale
- if !self.locale.nil?
- locale = self.locale
- else
- locale = I18n.locale
- end
- return locale.to_s
+ (self.locale || I18n.locale).to_s
end
def visible_comments
diff --git a/spec/controllers/public_body_controller_spec.rb b/spec/controllers/public_body_controller_spec.rb
index 3a42b535f..445128db7 100644
--- a/spec/controllers/public_body_controller_spec.rb
+++ b/spec/controllers/public_body_controller_spec.rb
@@ -43,18 +43,14 @@ describe PublicBodyController, "when showing a body" do
:conditions => ["public_body_id = ?", public_bodies(:humpadink_public_body).id])
end
- it "should assign the body using different locale from that used for url_name" do
- I18n.with_locale(:es) do
- get :show, {:url_name => "dfh", :view => 'all'}
- assigns[:public_body].notes.should == "Baguette"
- end
+ it "should redirect to the canonical name in the chosen locale" do
+ get :show, {:url_name => "dfh", :view => 'all', :show_locale => "es"}
+ response.should redirect_to "http://test.host/es/body/edfh"
end
it "should assign the body using same locale as that used in url_name" do
- I18n.with_locale(:es) do
- get :show, {:url_name => "edfh", :view => 'all'}
- assigns[:public_body].notes.should == "Baguette"
- end
+ get :show, {:url_name => "edfh", :view => 'all', :show_locale => "es"}
+ response.should contain("Baguette")
end
it "should redirect use to the relevant locale even when url_name is for a different locale" do
diff --git a/spec/models/public_body_spec.rb b/spec/models/public_body_spec.rb
index f247f561c..0b1bfccd7 100644
--- a/spec/models/public_body_spec.rb
+++ b/spec/models/public_body_spec.rb
@@ -378,7 +378,7 @@ describe PublicBody, " when loading CSV files" do
PublicBody.count.should == original_count + 3
- # XXX Not sure why trying to do a PublicBody.with_locale fails here. Seems related to
+ # XXX Not sure why trying to do a I18n.with_locale fails here. Seems related to
# the way categories are loaded every time from the PublicBody class. For now we just
# test some translation was done.
body = PublicBody.find_by_name('North West Fake Authority')