I've used your gem in an existing project which send localized emails and on first deploy I got some issues due to missing locale support. Here's my use case, I have a mailer which uses layouts and those layouts shows localized links something like
<%= link_to t('some_key'), some_url %>
I was sending messages directly in the controller and links and other translated stuff is localized correctly since in controller I18n.locale is set according to user locale. When I moved to resque_mailer obviously that code has stopped to work.
In my project I was able to retrieve user locale from the mailer and I've solved with this code in my mailer, but this is not always possible.
def mailer(user_id)
@user = User.find(user_id)
I18n.with_locale(@user.locale) { mail(...) }
end
The same issue can appear if mail content is timezone dependent (wasn't my case) so this should be handled by gem.
This could be solved with something like
# in deliver
env = {locale: I18n.locale, timezone: Time.zone.name}
resque.enqueue(@mailer_class, @method_name, env, *@args)
# in perform
I18n.with_locale(env['locale']) do
Time.use_zone(env['timezone']) do
message = self.send(:new, action, *args).message
message.deliver
end
end
This however would change main methods signatures, so it would need some specs.
What do you think? Are you interested in this kind of PR? Otherwise you should mention this issue in readme.
I've used your gem in an existing project which send localized emails and on first deploy I got some issues due to missing locale support. Here's my use case, I have a mailer which uses layouts and those layouts shows localized links something like
I was sending messages directly in the controller and links and other translated stuff is localized correctly since in controller
I18n.localeis set according to user locale. When I moved to resque_mailer obviously that code has stopped to work.In my project I was able to retrieve user locale from the mailer and I've solved with this code in my mailer, but this is not always possible.
The same issue can appear if mail content is timezone dependent (wasn't my case) so this should be handled by gem.
This could be solved with something like
This however would change main methods signatures, so it would need some specs.
What do you think? Are you interested in this kind of PR? Otherwise you should mention this issue in readme.