Default Locale

This commit is contained in:
saurabhbhatia 2013-09-06 16:41:02 +08:00
parent a3f1b8d54a
commit fa857cfeea
5 changed files with 36 additions and 15 deletions

View File

@ -145,11 +145,14 @@ class ApplicationController < ActionController::Base
condition = VALID_LOCALES.include?(session[:locale])
elsif session[:locale]
condition = @site.in_use_locales.include?(session[:locale])
elsif @site.default_locale.present?
default_locale = @site.default_locale
condition = @site.valid_locales.include?(default_locale)
else
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
session[:locale] = condition ? (default_locale || browser_locale || session[:locale]) : I18n.default_locale.to_s
I18n.locale = session[:locale].to_sym
@site_in_use_locales = site_locales_default_head(@site.in_use_locales)
@site_valid_locales = site_locales_default_head(@site.valid_locales)

View File

@ -1,9 +1,12 @@
class DesktopController< ApplicationController
layout 'desktop'
before_filter :authenticate_user!
before_filter :check_desktop_open, :only => [:index,:show]
#to load pages...
# caches_page :index
def index
@desktop = current_user.desktop
@currentusername = current_user.name
@ -336,6 +339,13 @@ class DesktopController< ApplicationController
render :json=>b.to_json
end
private
def check_desktop_open
if Me.desktop_closed && current_user.nil? #Need to be change
redirect_to '/admin/dashboards'
end
end
end

View File

@ -4,12 +4,6 @@ class PagesController < ApplicationController
before_filter :check_frontend_open, :only => [:index,:show]
# caches_page :index
def check_frontend_open
if Me.frontend_closed and current_user.nil? #Need to be change
redirect_to '/admin/dashboards'
end
end
def index
@item = Page.find_by_name('home')
@ -118,6 +112,12 @@ class PagesController < ApplicationController
raise PageError,'Missing Frontend Page' if @item.nil?
end
def check_frontend_open
if Me.frontend_closed && current_user.nil? #Need to be change
redirect_to '/admin/dashboards'
end
end
def save_from_no_lang_for_page
if @item.nil? or !@item.enabled_for_lang(I18n.locale.to_s)
flash[:error] = t('sys.module_page_lang_not_support')

View File

@ -14,10 +14,12 @@ class Site
field :frontend_closed, :type => Boolean, :default => false
field :backend_openness_on, :type => Boolean, :default => false
field :desktop_closed, :type => Boolean, :default => false
field :title_always_on, :type => Boolean, :default => false
field :dashbroad_allow_visitor, :type => Boolean, :default => false
field :mail_settings, :type => Hash
field :enabled_for, :type => Array, :default => nil
field :disk_space, :type => String
field :system_package_info, :type => Hash,:default=>{}
@ -34,6 +36,7 @@ class Site
field :sub_menu, localize: true
field :terms_of_user, localize: true
field :google_analytics
field :default_locale
field :mobile_on, :type => Boolean, :default => false

View File

@ -130,7 +130,7 @@
<div class="control-group">
<label class="control-label muted">Disable personal desktop</label>
<div class="controls">
<input type="checkbox" class="toggle-check" data-disabled="true">
<%= f.check_box :desktop_open , :class=>"toggle-check" %>
</div>
</div>
@ -138,24 +138,29 @@
<!-- Language -->
<div id="language-set" class="tab-pane fade">
<div class="control-group">
<!-- <div class="control-group">
<label class="control-label muted">Enable User Language Detection</label>
<div class="controls">
<input type="checkbox" class="toggle-check" data-disabled="true">
</div>
</div>
</div> -->
<div class="control-group">
<label class="control-label muted">Default Language</label>
<div class="controls">
<input type="radio" name="def-lang" class="toggle-check" data-disabled="true" data-title="English" checked="checked">
<input type="radio" name="def-lang" class="toggle-check" data-disabled="true" data-title="Chinese">
<% @site_in_use_locales.each do |locale| %>
<%= check_box_tag :default_locale, locale, :class=>"toggle-check" %>
<%= I18nVariable.from_locale(locale) %>
<% end %>
</div>
</div>
<div class="control-group">
<label class="control-label muted">Enable Language</label>
<div class="controls">
<input type="checkbox" class="toggle-check" data-disabled="true" data-title="English">
<input type="checkbox" class="toggle-check" data-disabled="true" data-title="Chinese">
<% @site_valid_locales.each do |valid_locale| %>
<%= check_box_tag 'site[enabled_for][]', valid_locale, (@site.enabled_for.nil?), :class=>"toggle-check" %>
<%= I18nVariable.from_locale(valid_locale) %>
<% end %>
<%= hidden_field_tag 'site[enabled_for][]', '' %>
</div>
</div>