From: Tom Hughes Date: Sun, 31 May 2009 16:10:53 +0000 (+0000) Subject: Send notification messages in the target user's language. X-Git-Tag: live~7335^2~8 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/5294e4d989038ae20c1e38622d14f5b54c7d830f Send notification messages in the target user's language. --- diff --git a/app/models/notifier.rb b/app/models/notifier.rb index c2ff4c53a..b291c2b57 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -108,6 +108,7 @@ private def common_headers(recipient) recipients recipient.email + locale recipient.preferred_language_from(I18n.available_locales) from "webmaster@openstreetmap.org" headers "return-path" => "bounces@openstreetmap.org", "Auto-Submitted" => "auto-generated" diff --git a/app/models/user.rb b/app/models/user.rb index f38994e53..683fcc96b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -90,6 +90,10 @@ class User < ActiveRecord::Base languages.find { |l| Language.find(:first, :conditions => { :code => l }) } end + def preferred_language_from(array) + (languages & array.collect { |i| i.to_s }).first + end + def nearby(radius = 50, num = 10) if self.home_lon and self.home_lat gc = OSM::GreatCircle.new(self.home_lat, self.home_lon) diff --git a/config/initializers/action_mailer.rb b/config/initializers/action_mailer.rb index db6c1b9b7..37510ac27 100644 --- a/config/initializers/action_mailer.rb +++ b/config/initializers/action_mailer.rb @@ -14,3 +14,25 @@ module Net 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