aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2015-08-04 11:56:57 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2015-08-04 11:56:57 +0200
commit7a3ca69959e312a215d5e8144fca79a08654fd89 (patch)
tree1f5d2c6191165aa6628074a015d5c5bea398c390 /activejob/lib
parent98ce161668d270390eb76db96bac9e1aa60cb0dd (diff)
parent3860e6b2bf486d8b27d433daab358dbc68ae3448 (diff)
downloadrails-7a3ca69959e312a215d5e8144fca79a08654fd89.tar.gz
rails-7a3ca69959e312a215d5e8144fca79a08654fd89.tar.bz2
rails-7a3ca69959e312a215d5e8144fca79a08654fd89.zip
Merge pull request #20800 from xijo/make_active_job_locale_aware
Make ActiveJob locale aware
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job/base.rb2
-rw-r--r--activejob/lib/active_job/core.rb7
-rw-r--r--activejob/lib/active_job/translation.rb11
3 files changed, 19 insertions, 1 deletions
diff --git a/activejob/lib/active_job/base.rb b/activejob/lib/active_job/base.rb
index fd49b3fda5..5d7c4cfb91 100644
--- a/activejob/lib/active_job/base.rb
+++ b/activejob/lib/active_job/base.rb
@@ -5,6 +5,7 @@ require 'active_job/enqueuing'
require 'active_job/execution'
require 'active_job/callbacks'
require 'active_job/logging'
+require 'active_job/translation'
module ActiveJob #:nodoc:
# = Active Job
@@ -60,6 +61,7 @@ module ActiveJob #:nodoc:
include Execution
include Callbacks
include Logging
+ include Translation
ActiveSupport.run_load_hooks(:active_job, self)
end
diff --git a/activejob/lib/active_job/core.rb b/activejob/lib/active_job/core.rb
index 0528572cd0..eac7279309 100644
--- a/activejob/lib/active_job/core.rb
+++ b/activejob/lib/active_job/core.rb
@@ -20,6 +20,9 @@ module ActiveJob
# ID optionally provided by adapter
attr_accessor :provider_job_id
+
+ # I18n.locale to be used during the job.
+ attr_accessor :locale
end
# These methods will be included into any Active Job object, adding
@@ -68,7 +71,8 @@ module ActiveJob
'job_class' => self.class.name,
'job_id' => job_id,
'queue_name' => queue_name,
- 'arguments' => serialize_arguments(arguments)
+ 'arguments' => serialize_arguments(arguments),
+ 'locale' => I18n.locale
}
end
@@ -96,6 +100,7 @@ module ActiveJob
self.job_id = job_data['job_id']
self.queue_name = job_data['queue_name']
self.serialized_arguments = job_data['arguments']
+ self.locale = job_data['locale'] || I18n.locale
end
private
diff --git a/activejob/lib/active_job/translation.rb b/activejob/lib/active_job/translation.rb
new file mode 100644
index 0000000000..67e4cf4ab9
--- /dev/null
+++ b/activejob/lib/active_job/translation.rb
@@ -0,0 +1,11 @@
+module ActiveJob
+ module Translation #:nodoc:
+ extend ActiveSupport::Concern
+
+ included do
+ around_perform do |job, block, _|
+ I18n.with_locale(job.locale, &block)
+ end
+ end
+ end
+end