aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb16
-rw-r--r--app/models/track_mailer.rb4
-rw-r--r--app/models/track_thing.rb16
-rw-r--r--app/models/user.rb9
-rw-r--r--app/models/user_mailer.rb2
-rw-r--r--app/views/track_mailer/event_digest.rhtml12
6 files changed, 40 insertions, 19 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 6d14d0d7a..a2a628f10 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -14,8 +14,14 @@ class ApplicationController < ActionController::Base
# Standard headers, footers and navigation for whole site
layout "default"
include FastGettext::Translation # make functions like _, n_, N_ etc available)
+
+ # Note: a filter stops the chain if it redirects or renders something
+ before_filter :authentication_check
before_filter :set_gettext_locale
+ before_filter :check_in_post_redirect
+ before_filter :session_remember_me
before_filter :set_vary_header
+
# scrub sensitive parameters from the logs
filter_parameter_logging :password
@@ -48,7 +54,14 @@ class ApplicationController < ActionController::Base
else
requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale
end
+ requested_locale = FastGettext.best_locale_in(requested_locale)
session[:locale] = FastGettext.set_locale(requested_locale)
+ if !@user.nil?
+ if @user.locale != requested_locale
+ @user.locale = session[:locale]
+ @user.save!
+ end
+ end
end
# scrub sensitive parameters from the logs
@@ -85,7 +98,6 @@ class ApplicationController < ActionController::Base
# Set cookie expiry according to "remember me" checkbox, as per "An easier
# and more flexible hack" on this page:
# http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions
- before_filter :session_remember_me
def session_remember_me
# Reset the "sliding window" session expiry time.
if request.env['rack.session.options']
@@ -263,7 +275,6 @@ class ApplicationController < ActionController::Base
end
# If we are in a faked redirect to POST request, then set post params.
- before_filter :check_in_post_redirect
def check_in_post_redirect
if params[:post_redirect] and session[:post_redirect_token]
post_redirect = PostRedirect.find_by_token(session[:post_redirect_token])
@@ -272,7 +283,6 @@ class ApplicationController < ActionController::Base
end
# Default layout shows user in corner, so needs access to it
- before_filter :authentication_check
def authentication_check
if session[:user_id]
@user = authenticated_user
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 4b7c603a7..f8bef4d61 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -85,7 +85,11 @@ class TrackMailer < ApplicationMailer
# If we have anything to send, then send everything for the user in one mail
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
end
# Record that we've now sent those alerts to that user
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 06514dd4e..b74f7dad5 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -192,16 +192,16 @@ class TrackThing < ActiveRecord::Base
if self.track_type == 'request_updates'
@params = {
# Website
- :list_description => "'<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_request}}', a request", :link_to_request => "<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Track this request by email"),
:verb_on_page_already => _("You are already tracking this request by email"),
# Email
- :title_in_email => "New updates for the request '" + self.info_request.title + "'",
- :title_in_rss => "New updates for the request '" + self.info_request.title + "'",
+ :title_in_email => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title),
+ :title_in_rss => _("New updates for the request '{{request_title}}'", :request_title => self.info_request.title),
# Authentication
- :web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'",
- :email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.",
- :email_subject => "Confirm you want to follow updates to the request '" + self.info_request.title + "'",
+ :web => _("To follow updates to the request '{{request_title}}'", :request_title => CGI.escapeHTML(self.info_request.title)),
+ :email => _("Then you will be emailed whenever the request '{{request_title}}' is updated.", :request_title => CGI.escapeHTML(self.info_request.title)),
+ :email_subject => _("Confirm you want to follow updates to the request '{{request_title}}'", :request_title => self.info_request.title),
# RSS sorting
:feed_sortby => 'newest'
}
@@ -243,7 +243,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'public_body_updates'
@params = {
# Website
- :list_description => "'<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>', a public authority", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_authority}}', a public authority", :link_to_authority => "<a href=\"/body/" + CGI.escapeHTML(self.public_body.url_name) + "\">" + CGI.escapeHTML(self.public_body.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Track requests to {{public_body_name}} by email",:public_body_name=>CGI.escapeHTML(self.public_body.name)),
:verb_on_page_already => _("You are already tracking requests to {{public_body_name}} by email", :public_body_name=>CGI.escapeHTML(self.public_body.name)),
# Email
@@ -259,7 +259,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'user_updates'
@params = {
# Website
- :list_description => "'<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>', a person", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => _("'{{link_to_user}}', a person", :link_to_user => "<a href=\"/user/" + CGI.escapeHTML(self.tracked_user.url_name) + "\">" + CGI.escapeHTML(self.tracked_user.name) + "</a>"), # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Track this person by email"),
:verb_on_page_already => _("You are already tracking this person by email"),
# Email
diff --git a/app/models/user.rb b/app/models/user.rb
index fddb6b035..c3c3da6f7 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -96,6 +96,15 @@ class User < ActiveRecord::Base
end
end
end
+
+ def get_locale
+ if !self.locale.nil?
+ locale = self.locale
+ else
+ locale = I18n.locale
+ end
+ return locale.to_s
+ end
def visible_comments
self.comments.find(:all, :conditions => 'visible')
diff --git a/app/models/user_mailer.rb b/app/models/user_mailer.rb
index 0972e167d..7adf5b63c 100644
--- a/app/models/user_mailer.rb
+++ b/app/models/user_mailer.rb
@@ -46,7 +46,5 @@ class UserMailer < ApplicationMailer
@body[:old_email] = old_email
@body[:new_email] = new_email
end
-
-
end
diff --git a/app/views/track_mailer/event_digest.rhtml b/app/views/track_mailer/event_digest.rhtml
index 46f230da1..089b778f8 100644
--- a/app/views/track_mailer/event_digest.rhtml
+++ b/app/views/track_mailer/event_digest.rhtml
@@ -18,17 +18,17 @@
# e.g. Julian Burgess sent a request to Royal Mail Group (15 May 2008)
if event.event_type == 'response'
url = main_url(incoming_message_url(event.incoming_message))
- main_text += event.info_request.public_body.name + " sent a response to " + event.info_request.user.name
+ main_text += _("{{public_body}} sent a response to {{user_name}}", :public_body => event.info_request.public_body.name, :user_name => event.info_request.user.name)
elsif event.event_type == 'followup_sent'
url = main_url(outgoing_message_url(event.outgoing_message))
- main_text += event.info_request.user.name + " sent a follow up message to " + event.info_request.public_body.name
+ main_text += _("{{user_name}} sent a follow up message to {{public_body}}", :user_name => event.info_request.user.name, :public_body => event.info_request.public_body.name)
elsif event.event_type == 'sent'
# this is unlikely to happen in real life, but happens in the test code
url = main_url(outgoing_message_url(event.outgoing_message))
- main_text += event.info_request.user.name + " sent a request to " + event.info_request.public_body.name
+ main_text += _("{{user_name}} sent a request to {{public_body}}", :user_name => event.info_request.user.name, :public_body => event.info_request.public_body.name)
elsif event.event_type == 'comment'
url = main_url(comment_url(event.comment))
- main_text += event.comment.user.name + " added an annotation"
+ main_text += _("{{user_name}} added an annotation", :user_name => event.comment.user.name)
else
raise "unknown type in event_digest " + event.event_type
end
@@ -57,10 +57,10 @@
main_text += "\n"
end
-%><%=main_text%>Alter your subscription
+%><%=main_text%><%= _("Alter your subscription")%>
=======================
-Please click on the link below to cancel or alter these emails.
+<% _("Please click on the link below to cancel or alter these emails.") %>
<%=@unsubscribe_url%>
-- <%= _('the {{site_name}} team', :site_name=>site_name) %>