Module: Wurk::Middleware::I18n
- Defined in:
- lib/wurk/middleware/i18n.rb
Overview
Propagates I18n.locale from the enqueueing process to the worker.
Auto-registered when this file is required: Client onto the
client_middleware chain, Server onto server_middleware.
No-op when the I18n constant is undefined (no i18n gem loaded);
the middleware survives the absence and just passes the job through.
Job hash key: "locale" (matches Sidekiq spec ยง2.2).
Defined Under Namespace
Class Method Summary collapse
Class Method Details
.current_locale ⇒ Object
17 18 19 |
# File 'lib/wurk/middleware/i18n.rb', line 17 def current_locale ::I18n.locale.to_s if defined?(::I18n) end |
.with_locale(locale) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/wurk/middleware/i18n.rb', line 21 def with_locale(locale) return yield unless defined?(::I18n) && locale previous = ::I18n.locale ::I18n.locale = locale begin yield ensure ::I18n.locale = previous end end |