]> source.dussan.org Git - redmine.git/commitdiff
Fixed: browser's accept-language subcodes ignored (#1320).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 30 May 2008 18:40:02 +0000 (18:40 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 30 May 2008 18:40:02 +0000 (18:40 +0000)
git-svn-id: http://redmine.rubyforge.org/svn/trunk@1481 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/application.rb
test/functional/welcome_controller_test.rb

index abf62164132805521d507c982f77233aadbdf006..2daee50de6c3c38aeb12c2d7d884d5519ce3b2b1 100644 (file)
@@ -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
index 18146c6aa86bced7ac5ff7a4f51cbfdd54295bdb..3e1308ef1333e24cbd49da8f27150dca19604c53 100644 (file)
@@ -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