diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 778a7927..f8f55c64 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -140,21 +140,23 @@ class ApplicationController < ActionController::Base # update session if passed session[:locale] = params[:locale] if params[:locale] browser_locale = condition = nil - default_locale = @site.default_locale if @site.default_locale.present? - # check if locale is valid for non site pages + default_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) condition = VALID_LOCALES.include?(session[:locale]) - elsif session[:locale] - condition = @site.in_use_locales.include?(session[:locale]) + #check if the default locale is present or not elsif @site.default_locale.present? default_locale = @site.default_locale - condition = @site.valid_locales.include?(default_locale) - else + condition = @site.in_use_locales.include?(default_locale) + elsif !@site.enable_language_detection + #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 session[:locale] + condition = @site.in_use_locales.include?(session[:locale]) end - session[:locale] = condition ? ( browser_locale || session[:locale] || default_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) diff --git a/app/models/site.rb b/app/models/site.rb index 5304a9d4..32ea8835 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -7,6 +7,7 @@ class Site field :in_use_locales, :type => Array field :valid_locales, :type => Array + field :enable_locales, :type => Array field :roaming_id field :private_key, :type => Binary @@ -17,6 +18,7 @@ class Site field :desktop_closed, :type => Boolean, :default => false field :sitemap_menu_in_header, :type => Boolean, :default => false field :enable_terms_of_use, :type => Boolean, :default => false + field :enable_language_detection, :type => Boolean, :default => false field :title_always_on, :type => Boolean, :default => false field :dashbroad_allow_visitor, :type => Boolean, :default => false @@ -44,6 +46,21 @@ class Site belongs_to :design has_many :site_metas, :autosave => true, :dependent => :destroy + validate :in_use_locales, :minimum_enabled_locales + + def minimum_enabled_locales + size = self.in_use_locales.length + if size < 1 + errors.add(:size, "Needs at least one language in use") + end + end + + def maximum_enabled_locales + size = self.in_use_locales.length + if size >= 2 + errors.add(:size, "Max 2 ") + end + end def generate_keys private_key = OpenSSL::PKey::RSA.generate(2048) diff --git a/app/views/admin/designs/_design.html.erb b/app/views/admin/designs/_design.html.erb index 3b557d5e..24c99b41 100644 --- a/app/views/admin/designs/_design.html.erb +++ b/app/views/admin/designs/_design.html.erb @@ -1,4 +1,3 @@ -<%= Rails.logger.info"@@@@@@@@@@@@@@@@"+design.inspect%>