From 52522c102e7995226c7ce1d288a1b58358d5e51d Mon Sep 17 00:00:00 2001 From: "livefromthemoon@gmail.com" Date: Thu, 28 Oct 2010 18:09:25 +0200 Subject: [PATCH] add some basic verification when loading the languages config file --- app/controllers/application_controller.rb | 1 + config/environment.rb | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2ab2838c2..3e32d4c27 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -35,6 +35,7 @@ class ApplicationController < ActionController::Base end def set_locale + I18n.default_locale = DEFAULT_LANGUAGE if current_user I18n.locale = current_user.language else diff --git a/config/environment.rb b/config/environment.rb index e95579b99..9afe20c52 100644 --- a/config/environment.rb +++ b/config/environment.rb @@ -21,9 +21,9 @@ end if File.exists?(File.expand_path("./config/languages.yml")) languages = YAML::load(File.open(File.expand_path("./config/languages.yml"))) - AVAILABLE_LANGUAGES = languages['available'] - DEFAULT_LANGUAGE = languages['default'] - AVAILABLE_LANGUAGE_CODES = languages['available'].keys.map { |v| v.to_s} + AVAILABLE_LANGUAGES = (languages['available'].length > 0) ? languages['available'] : { :en => 'English' } + DEFAULT_LANGUAGE = (AVAILABLE_LANGUAGES.include?(languages['default'])) ? languages['default'] : AVAILABLE_LANGUAGES.keys[0].to_s + AVAILABLE_LANGUAGE_CODES = languages['available'].keys.map { |v| v.to_s } else AVAILABLE_LANGUAGES = { :en => 'English' } DEFAULT_LANGUAGES = 'en'