Set I18n from browser
This commit is contained in:
parent
6abf53f34d
commit
8374bc8d12
|
@ -13,7 +13,7 @@ class ApplicationController < ActionController::Base
|
||||||
layout :layout_by_resource
|
layout :layout_by_resource
|
||||||
|
|
||||||
helper :admin, :orbit_form
|
helper :admin, :orbit_form
|
||||||
before_filter :set_locale, :set_site, :prepare_for_mobile
|
before_filter :set_site, :set_locale, :prepare_for_mobile
|
||||||
|
|
||||||
helper_attr :site_valid_locales
|
helper_attr :site_valid_locales
|
||||||
|
|
||||||
|
@ -154,18 +154,18 @@ class ApplicationController < ActionController::Base
|
||||||
def set_locale
|
def set_locale
|
||||||
# update session if passed
|
# update session if passed
|
||||||
session[:locale] = params[:locale] if params[:locale]
|
session[:locale] = params[:locale] if params[:locale]
|
||||||
|
browser_locale = condition = nil
|
||||||
# set locale based on session or default
|
# check if locale is valid for non site pages
|
||||||
begin
|
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s)
|
||||||
# check if locale is valid for non site pages
|
condition = VALID_LOCALES.include?(session[:locale])
|
||||||
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
|
elsif session[:locale]
|
||||||
I18n.locale = I18n.default_locale
|
condition = @site_in_use_locales.include?(session[:locale])
|
||||||
else
|
else
|
||||||
I18n.locale = session[:locale]
|
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil
|
||||||
end
|
condition = @site_in_use_locales.include?(browser_locale)
|
||||||
rescue
|
end
|
||||||
I18n.locale = I18n.default_locale
|
session[:locale] = condition ? (browser_locale || session[:locale]) : I18n.default_locale.to_s
|
||||||
end
|
I18n.locale = session[:locale].to_sym
|
||||||
end
|
end
|
||||||
|
|
||||||
# Set the site variables
|
# Set the site variables
|
||||||
|
|
Reference in New Issue