You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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_tot('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.
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 deliverenv={locale: I18n.locale,timezone: Time.zone.name}resque.enqueue(@mailer_class,@method_name,env, *@args)# in performI18n.with_locale(env['locale'])doTime.use_zone(env['timezone'])domessage=self.send(:new,action, *args).messagemessage.deliverendend
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.
The text was updated successfully, but these errors were encountered:
Hmm interesting. I admittedly haven't had the need to send localized emails myself, but if others have this issue it's certainly a concern.
That said, I don't love the solution of changing the global state to achieve it, and changing the method signature is undesirable, potentially breaking for users with mail in-queue... So that would have to be managed. Otoh to your point, it stinks if users have to create a locale field to reference for each mailer method that cares of course. This is also Rails-specific and not all users of RM are using Rails, so that's something to consider.
Happy to discuss further. Thanks for pointing this out.
# pop and set locale from the args before runningmodulePerformWithLocaledefperform(*args)I18n.with_locale(args.pop)dosuper(*args)endendendmoduleDeliverWithLocaledefdeliver# @args are not used when rendered inline, only when enqueueing@args << I18n.locale.to_ssuperendend#= resque_mailer locale supportifdefined?(Resque::Mailer)moduleResque::Mailer# push locale onto the args when queueingMessageDecoy.send:prepend,DeliverWithLocale# pop when dequeueingClassMethods.send:prepend,PerformWithLocaleendend
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.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.
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.
The text was updated successfully, but these errors were encountered: