Skip to content

Instantly share code, notes, and snippets.

@tchak
Created March 19, 2013 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tchak/5195931 to your computer and use it in GitHub Desktop.
Save tchak/5195931 to your computer and use it in GitHub Desktop.
LocalizedJob
module LocalizedJob
module InstanceMethods
def send_later_with_i18n(method, locale, *args)
locale ||= I18n.locale
job = LocalizedJob::LocalizedMethod.new(self, method.to_sym, args)
job.locale = locale
Delayed::Job.enqueue job
end
end
class LocalizedMethod < Delayed::PerformableMethod
attr_accessor :locale
def perform
prev_locale = I18n.locale
I18n.locale = self.locale
super
I18n.locale = prev_locale
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment