Created
June 6, 2010 08:30
-
-
Save RSpace/427425 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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