Rails 2.3 I18n and localized mailer templates

72 views
Skip to first unread message

Joost

unread,
Feb 23, 2009, 10:04:55 AM2/23/09
to rails-i18n
I don't seem to get Rails 2.3 to render my localized mailer templates.
Is it supported?

I tried: user_mailer/somemailer_notification.nl.text.plain.erb (nl =
I18n.locale)
and: user_mailer/somemailer_notification.text.plain.nl.erb

Thanks!

Joost

unread,
Feb 24, 2009, 5:38:20 AM2/24/09
to rails-i18n
I think it is not? When I look at the commits in
http://weblog.rubyonrails.org/2009/1/31/this-week-in-edge-rails ?

Anybody who knows about a plugin that does this? I checked Github but
found nothing..

Joost

unread,
Feb 25, 2009, 5:03:49 AM2/25/09
to rails-i18n
This seems to all be related to the regexp not matching
'mailer_template.nl.text.plain.erb'..

A fix from Krzysztof Knapik:

module ActionView #:nodoc:
class Template

def split(file)
if m = file.match(/^(.*\/)?([^\.]+)\.(.*)$/)
base_path = m[1]
name = m[2]
extensions = m[3]
else
return
end

locale = nil
format = nil
extension = nil

# This code deosn't work for multiformat locale templates e.g.
nl.text.plain.erb
# if m = extensions.match(/^(\w+)?\.?(\w+)?\.?(\w+)?\.?/)
# if valid_locale?(m[1]) && m[2] && valid_extension?(m[3]) #
All three
# locale = m[1]
# format = m[2]
# extension = m[3]
# elsif m[1] && m[2] && valid_extension?(m[3]) # Multipart
formats
# format = "#{m[1]}.#{m[2]}"
# extension = m[3]
# elsif valid_locale?(m[1]) && valid_extension?(m[2]) # locale
and extension
# locale = m[1]
# extension = m[2]
# elsif valid_extension?(m[2]) # format and extension
# format = m[1]
# extension = m[2]
# elsif valid_extension?(m[1]) # Just extension
# extension = m[1]
# else # No extension
# format = m[1]
# end
# end
m = extensions.split('.')
if valid_extension?(m[-1])
extension = m[-1]
if valid_locale?(m[0]) || valid_locale?(m[0].split('-')[0])
locale = m[0]
format = m[1..-2].join('.')
else
format = m[0..-2].join('.')
end
else
format = m.join('.')
end
format = nil if format.blank?
[base_path, name, locale, format, extension]
end
end
end
Reply all
Reply to author
Forward
0 new messages