Fixed application locale

This commit is contained in:
saurabhbhatia 2013-11-28 12:28:43 +08:00
parent 8e6cf99b08
commit 1a4c689ee6
3 changed files with 6 additions and 3 deletions

View File

@ -147,6 +147,7 @@ class ApplicationController < ActionController::Base
session[:locale] = params[:locale] if params[:locale]
browser_locale = condition = nil
default_locale = condition = nil
backup_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)
@ -161,9 +162,11 @@ class ApplicationController < ActionController::Base
#check enable langauge detection
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil
condition = @site.in_use_locales.include?(browser_locale)
elsif (@site.default_locale.nil? && @site.enable_language_detection.eql?(false))
condition = @site.valid_locales.first
end
session[:locale] = condition ? (browser_locale || session[:locale] || default_locale) : I18n.default_locale.to_s
session[:locale] = condition ? (browser_locale || session[:locale] || default_locale || backup_locale) : I18n.default_locale.to_s
I18n.locale = session[:locale].to_sym
@site_in_use_locales = @site.in_use_locales
@site_valid_locales = site_locales_default_head(@site.valid_locales)

View File

@ -14,7 +14,7 @@
<li title="Site Info"><%= link_to admin_site_site_info_path(@site), :class => active_for_action('sites', 'site_info') do %><span><i class="icons-browser"></i></span><%end%></li>
<li title="Site Mobile"><%= link_to admin_site_responsive_setting_path(@site), :class => active_for_action('sites', 'responsive_setting') do %><span><i class="icons-mobile"></i></span><%end%></li>
<li title="Mobile Setting"><%= link_to admin_site_responsive_setting_path(@site), :class => active_for_action('sites', 'responsive_setting') do %><span><i class="icons-mobile"></i></span><%end%></li>
<li title="Search Engine"><%= link_to admin_site_search_engine_path(@site), :class => active_for_action('sites', 'search_engine') do %><span><i class="icons-search"></i></span><%end%></li>

View File

@ -14,7 +14,7 @@
<li title="Site Info"><%= link_to admin_site_site_info_path(@site), :class => active_for_action('sites', 'site_info') do %><span><i class="icons-browser"></i></span><%end%></li>
<li title="Site Mobile"><%= link_to admin_site_responsive_setting_path(@site), :class => active_for_action('sites', 'responsive_setting') do %><span><i class="icons-mobile"></i></span><%end%></li>
<li title="Mobile Setting"><%= link_to admin_site_responsive_setting_path(@site), :class => active_for_action('sites', 'responsive_setting') do %><span><i class="icons-mobile"></i></span><%end%></li>
<li title="Search Engine"><%= link_to admin_site_search_engine_path(@site), :class => active_for_action('sites', 'search_engine') do %><span><i class="icons-search"></i></span><%end%></li>