Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Inject locale into Resque::Mailer and Devise::Async

View async_emails_i18n.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
require 'resque_mailer'
require 'devise/async'
 
# pop and set locale from the args before running
module PerformWithLocale
def perform(*args)
I18n.with_locale(args.pop) do
super(*args)
end
end
end
 
module DeliverWithLocale
def deliver
# @args are not used when rendered inline, only when enqueueing
@args << I18n.locale.to_s
super
end
end
 
#= resque_mailer locale support
if defined?(Resque::Mailer)
module Resque::Mailer
# push locale onto the args when queueing
MessageDecoy.send :prepend, DeliverWithLocale
# pop when dequeueing
ClassMethods.send :prepend, PerformWithLocale
end
end
 
#= devise/async locale support
if defined?(Devise::Async)
module Devise::Async
module EnqueueWithLocale
def enqueue(*args)
super *(args + [I18n.locale])
end
end
class Worker
class << self
prepend Devise::Async::EnqueueWithLocale
end
end
class Backend::Resque
class << self
prepend PerformWithLocale
end
end
end
end
 
 
 
Owner

requires ruby 2 and this devise-async PR https://github.com/mhfs/devise-async/pull/37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.