Send notification messages in the target user's language.

This commit is contained in:
Tom Hughes 2009-05-31 16:10:53 +00:00
parent f4f0c4b155
commit 5294e4d989
3 changed files with 27 additions and 0 deletions

View file

@ -108,6 +108,7 @@ private
def common_headers(recipient) def common_headers(recipient)
recipients recipient.email recipients recipient.email
locale recipient.preferred_language_from(I18n.available_locales)
from "webmaster@openstreetmap.org" from "webmaster@openstreetmap.org"
headers "return-path" => "bounces@openstreetmap.org", headers "return-path" => "bounces@openstreetmap.org",
"Auto-Submitted" => "auto-generated" "Auto-Submitted" => "auto-generated"

View file

@ -90,6 +90,10 @@ class User < ActiveRecord::Base
languages.find { |l| Language.find(:first, :conditions => { :code => l }) } languages.find { |l| Language.find(:first, :conditions => { :code => l }) }
end end
def preferred_language_from(array)
(languages & array.collect { |i| i.to_s }).first
end
def nearby(radius = 50, num = 10) def nearby(radius = 50, num = 10)
if self.home_lon and self.home_lat if self.home_lon and self.home_lat
gc = OSM::GreatCircle.new(self.home_lat, self.home_lon) gc = OSM::GreatCircle.new(self.home_lat, self.home_lon)

View file

@ -14,3 +14,25 @@ module Net
end end
end end
end end
# Monkey patch to allow sending of messages in specific locales
module ActionMailer
class Base
adv_attr_accessor :locale
private
alias_method :old_render_message, :render_message
def render_message(method_name, body)
old_locale= I18n.locale
begin
I18n.locale = @locale
message = old_render_message(method_name, body)
ensure
I18n.locale = old_locale
end
message
end
end
end