app/api/locomotive/api/middlewares/locale_middleware.rb in locomotivecms-3.1.0.rc1 vs app/api/locomotive/api/middlewares/locale_middleware.rb in locomotivecms-3.1.0.rc2
- old
+ new
@@ -15,10 +15,11 @@
# 3. check for the site default locale
# 4. if none, take the default locomotive locale
#
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
@@ -28,9 +29,16 @@
env['HTTP_X_LOCOMOTIVE_LOCALE'].presence ||
params(env)[:locale].presence ||
params(env)['locale'].presence ||
env['locomotive.site'].try(:default_locale).presence ||
Locomotive.config.site_locales.first
+ end
+
+ def setup_i18n_fallback(site)
+ ::Mongoid::Fields::I18n.clear_fallbacks
+ (site.try(:locales) || []).each do |locale|
+ ::Mongoid::Fields::I18n.fallbacks_for(locale, site.locale_fallbacks(locale))
+ end
end
def params(env)
@params ||= Rack::Request.new(env).params
end