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
|
||||
|
||||
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
|
||||
|
||||
|
@ -154,18 +154,18 @@ class ApplicationController < ActionController::Base
|
|||
def set_locale
|
||||
# update session if passed
|
||||
session[:locale] = params[:locale] if params[:locale]
|
||||
|
||||
# set locale based on session or default
|
||||
begin
|
||||
browser_locale = condition = nil
|
||||
# check if locale is valid for non site pages
|
||||
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s) && !VALID_LOCALES.include?(session[:locale])
|
||||
I18n.locale = I18n.default_locale
|
||||
if LIST[:forbidden_item_names].include?(env['PATH_INFO'].split('/')[1].to_s)
|
||||
condition = VALID_LOCALES.include?(session[:locale])
|
||||
elsif session[:locale]
|
||||
condition = @site_in_use_locales.include?(session[:locale])
|
||||
else
|
||||
I18n.locale = session[:locale]
|
||||
end
|
||||
rescue
|
||||
I18n.locale = I18n.default_locale
|
||||
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil
|
||||
condition = @site_in_use_locales.include?(browser_locale)
|
||||
end
|
||||
session[:locale] = condition ? (browser_locale || session[:locale]) : I18n.default_locale.to_s
|
||||
I18n.locale = session[:locale].to_sym
|
||||
end
|
||||
|
||||
# Set the site variables
|
||||
|
|
Reference in New Issue