Browse Source

Fixed language detection for our preview environment

development
Godwin 9 years ago
parent
commit
b1ecb5ace5
  1. 14
      app/controllers/application_controller.rb
  2. 2
      app/views/layouts/application.html.haml
  3. 5
      config/application.rb

14
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

2
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' }

5
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

Loading…
Cancel
Save