From 880ca238add8e81c460650d02bf261d6cfef1b91 Mon Sep 17 00:00:00 2001 From: Andreas Stephanides Date: Sun, 12 Jul 2015 09:41:02 +0200 Subject: [PATCH] fix locale 2 --- app/controllers/application_controller.rb | 11 ++++++++--- app/controllers/home_controller.rb | 4 +++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 09831c2..436163b 100755 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,19 +1,24 @@ class ApplicationController < ActionController::Base protect_from_forgery before_filter :set_i18n_locale_from_params + protected theme :get_theme + def set_i18n_locale_from_params if params[:locale] if I18n.available_locales.include?(params[:locale].to_sym) - I18n.locale=params[:locale].to_sym + session[:locale] = params[:locale] + else flash.now[:notice]= "#{params[:locale]} translation not available" logger.error flash.now[:notice] + end - else - I18n.locale = session[:locale] || :de end + I18n.locale = session[:locale] || request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^de|en/).first || I18n.default_locale + + session[:locale] = I18n.locale end diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 630356e..d177155 100755 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -95,7 +95,9 @@ class HomeController < ApplicationController end end def language - redirect_to request.referer || root_path + redirect_to :back + rescue ActionController::RedirectBackError + redirect_to :root end def choose_contact_topics authorize! :doadmin, User