Class: Zaikio::Client::Helpers::LocaleMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zaikio/client/helpers/locale_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, disable_i18n: false) ⇒ LocaleMiddleware

Returns a new instance of LocaleMiddleware.



7
8
9
10
# File 'lib/zaikio/client/helpers/locale_middleware.rb', line 7

def initialize(app, disable_i18n: false)
  @disable_i18n = disable_i18n
  super(app)
end

Instance Method Details

#call(request_env) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/zaikio/client/helpers/locale_middleware.rb', line 12

def call(request_env)
  if !@disable_i18n && Object.const_defined?("I18n")
    request_env[:request_headers]["Accept-Language"] = ::I18n.try(:locale)&.to_s
  end

  @app.call(request_env)
end