Commit f10b6bd5 authored by o@immerda.ch's avatar o@immerda.ch
Browse files

fix locale selection, when locale is not available

parent a3dd9a94
......@@ -7,12 +7,17 @@ class ApplicationController < ActionController::Base
before_action :set_locale
def valid_l(l)
return l if l && I18n.available_locales.include?(l)
nil
end
def extract_locale
(request.env['HTTP_ACCEPT_LANGUAGE']||'').scan(/^[a-z]{2}/).first
(request.env['HTTP_ACCEPT_LANGUAGE']||'').scan(/^[a-z]{2}/).select{|l| valid_l(l)}.first
end
def set_locale
I18n.locale = params[:l] || session[:locale] || extract_locale || I18n.default_locale
I18n.locale = valid_l(params[:l]) || valid_l(session[:locale]) || extract_locale || I18n.default_locale
session[:locale] = I18n.locale
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment