Class: Locomotive::API::Middlewares::LocaleMiddleware
- Inherits:
-
Object
- Object
- Locomotive::API::Middlewares::LocaleMiddleware
- Defined in:
- app/api/locomotive/api/middlewares/locale_middleware.rb
Instance Method Summary collapse
-
#call(env) ⇒ Object
Rules (order is important):.
-
#initialize(app) ⇒ LocaleMiddleware
constructor
A new instance of LocaleMiddleware.
Constructor Details
#initialize(app) ⇒ LocaleMiddleware
Returns a new instance of LocaleMiddleware.
7 8 9 |
# File 'app/api/locomotive/api/middlewares/locale_middleware.rb', line 7 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
Rules (order is important):
-
check for the X-Locomotive-Locale header
-
check for the locale request param
-
check for the site default locale
-
if none, take the default locomotive locale
18 19 20 21 22 23 24 |
# File 'app/api/locomotive/api/middlewares/locale_middleware.rb', line 18 def call(env) locale = find_locale(env) setup_i18n_fallback(env['locomotive.site']) ::Mongoid::Fields::I18n.with_locale(locale) do @app.call(env) end end |