summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application.rb6
-rw-r--r--test/functional/welcome_controller_test.rb7
2 files changed, 10 insertions, 3 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index abf621641..2daee50de 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -61,11 +61,11 @@ class ApplicationController < ActionController::Base
def set_localization
User.current.language = nil unless User.current.logged?
lang = begin
- if !User.current.language.blank? and GLoc.valid_languages.include? User.current.language.to_sym
+ if !User.current.language.blank? && GLoc.valid_language?(User.current.language)
User.current.language
elsif request.env['HTTP_ACCEPT_LANGUAGE']
- accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.split('-').first
- if accept_lang and !accept_lang.empty? and GLoc.valid_languages.include? accept_lang.to_sym
+ accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first.downcase
+ if !accept_lang.blank? && (GLoc.valid_language?(accept_lang) || GLoc.valid_language?(accept_lang = accept_lang.split('-').first))
User.current.language = accept_lang
end
end
diff --git a/test/functional/welcome_controller_test.rb b/test/functional/welcome_controller_test.rb
index 18146c6aa..3e1308ef1 100644
--- a/test/functional/welcome_controller_test.rb
+++ b/test/functional/welcome_controller_test.rb
@@ -46,4 +46,11 @@ class WelcomeControllerTest < Test::Unit::TestCase
get :index
assert_equal :fr, @controller.current_language
end
+
+ def test_browser_language_alternate
+ Setting.default_language = 'en'
+ @request.env['HTTP_ACCEPT_LANGUAGE'] = 'zh-TW'
+ get :index
+ assert_equal :"zh-tw", @controller.current_language
+ end
end