Sha256: 266f51bb259e31a55898f1790d64cefe6bfd6d6b9f83f81bca783009a9bd4924

Contents?: true

Size: 828 Bytes

Versions: 11

Compression:

Stored size: 828 Bytes

Contents

module Sidekiq::Middleware::I18n
  # Get the current locale and store it in the message
  # to be sent to Sidekiq.
  class Client
    def call(worker_class, msg, queue)
      msg['locale'] ||= I18n.locale
      yield
    end
  end

  # Pull the msg locale out and set the current thread to use it.
  class Server
    def call(worker, msg, queue)
      I18n.locale = msg['locale'] || I18n.default_locale
      yield
    ensure
      I18n.locale = nil
    end
  end
end

Sidekiq.configure_client do |config|
  config.client_middleware do |chain|
    chain.add Sidekiq::Middleware::I18n::Client
  end
end

Sidekiq.configure_server do |config|
  config.client_middleware do |chain|
    chain.add Sidekiq::Middleware::I18n::Client
  end
  config.server_middleware do |chain|
    chain.add Sidekiq::Middleware::I18n::Server
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
sidekiq-2.17.1 lib/sidekiq/middleware/i18n.rb
sidekiq-2.17.0 lib/sidekiq/middleware/i18n.rb
sidekiq-2.16.1 lib/sidekiq/middleware/i18n.rb
sidekiq-2.16.0 lib/sidekiq/middleware/i18n.rb
sidekiq-2.15.2 lib/sidekiq/middleware/i18n.rb
sidekiq-2.15.1 lib/sidekiq/middleware/i18n.rb
sidekiq-2.15.0 lib/sidekiq/middleware/i18n.rb
sidekiq-2.14.1 lib/sidekiq/middleware/i18n.rb
sidekiq-2.14.0 lib/sidekiq/middleware/i18n.rb
sidekiq-2.13.1 lib/sidekiq/middleware/i18n.rb
sidekiq-2.13.0 lib/sidekiq/middleware/i18n.rb