Skip to content

Instantly share code, notes, and snippets.

@RSpace
Created June 6, 2010 08:30
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 RSpace/427425 to your computer and use it in GitHub Desktop.
Save RSpace/427425 to your computer and use it in GitHub Desktop.
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_with_i18n
prev_locale = I18n.locale
I18n.locale = self.locale
perform_without_i18n
I18n.locale = prev_locale
end
alias_method_chain :perform, :i18n
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment