From b1ecb5ace5d2c2418d06d9b2e4c605dc9ac54751 Mon Sep 17 00:00:00 2001 From: Godwin Date: Sun, 3 May 2015 15:08:54 -0700 Subject: [PATCH] Fixed language detection for our preview environment --- app/controllers/application_controller.rb | 14 ++++++++++---- app/views/layouts/application.html.haml | 2 +- config/application.rb | 5 +++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e226e7b..ada929a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -7,10 +7,6 @@ class ApplicationController < LinguaFrancaApplicationController # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception - - #if ENV['RAILS_ENV'] || 'production' - # force_ssl only: :success - #end before_filter :capture_page_info @@ -21,12 +17,22 @@ class ApplicationController < LinguaFrancaApplicationController #u = User.find_by_email('goodgodwin@hotmail.com') #auto_login(u) #logout() + + # set the translator to the current user if we're logged in I18n.config.translator = current_user + + # get the current confernece and set it globally @conference = Conference.order("start_date DESC").first + + # add some style sheets @stylesheets ||= Array.new + # add the translations stylesheet if translating @stylesheets << params[:controller] if params[:controller] == 'translations' ActionMailer::Base.default_url_options = {:host => "#{request.protocol}#{request.host_with_port}"} + + # call the base method to detect the language + super end def home diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index 684ff8c..07947dc 100644 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -7,7 +7,7 @@ %meta{ name: 'description', content: (yield_or_default :description, I18n.t('page_descriptions.home')) } = csrf_meta_tags = inject_css! - - @stylesheets.each do |css| + - (@stylesheets || []).each do |css| = inject_css! css %link{ href: asset_path('favicon.ico'), rel: 'shortcut icon', type: 'image/x-icon' } %link{ href: asset_path('favicon.ico'), rel: 'icon', type: 'image/x-icon' } diff --git a/config/application.rb b/config/application.rb index cb59fb5..d4dc028 100644 --- a/config/application.rb +++ b/config/application.rb @@ -28,5 +28,10 @@ module BikeBike config.i18n.enforce_available_locales = false self.paths['config/database'] = Rails.root.join('config', 'database.yml') config.active_record.raise_in_transactional_callbacks = true + + # detect the language using the subdimain + I18n.config.language_detection_method = I18n::Config::DETECT_LANGUAGE_FROM_SUBDOMAIN + # if we are in our preview environment, set the locale regex to detect the preview- prefix + I18n.config.host_locale_regex = /^preview\-([a-z]{2})\.bikebike\.org$/ if Rails.env == 'preview' end end