Created
March 19, 2013 13:04
-
-
Save tchak/5195931 to your computer and use it in GitHub Desktop.
LocalizedJob
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 | |
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