]> git.openstreetmap.org Git - rails.git/commitdiff
Fix compatible_language_from in the http_accept_language plugin to
authorTom Hughes <tom@compton.nu>
Wed, 15 Jul 2009 23:42:56 +0000 (23:42 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 15 Jul 2009 23:42:56 +0000 (23:42 +0000)
correctly follow the RFC 2616 language selection algorithm and then
revert to the previous way of selecting languages.

app/controllers/application_controller.rb
vendor/plugins/http_accept_language/lib/http_accept_language.rb

index 00104b0a174d618292cf0958c0d4c00c693e7c5a..0d6cdea6424fea77b93e32e047796546008a1637 100644 (file)
@@ -110,9 +110,8 @@ class ApplicationController < ActionController::Base
       end
     end
 
-    I18n.locale = request.preferred_language_from(I18n.available_locales) ||
-                  request.compatible_language_from(I18n.available_locales)
-    logger.info("Select #{I18n.locale} matching #{request.user_preferred_languages.join(',')} against #{I18n.available_locales.join(',')}")
+    I18n.locale = request.compatible_language_from(I18n.available_locales)
+
     response.headers['Content-Language'] = I18n.locale.to_s
   end
 
index 85ee89c95d8885f80bff36be063efd4d429b8a9e..1bedd6c742ff28e9793576688bd8a05aefe15185 100644 (file)
@@ -48,9 +48,8 @@ module HttpAcceptLanguage
   #
   def compatible_language_from(array)
     user_preferred_languages.map do |x|
-      x = x.to_s.split("-")[0]
       array.find do |y|
-        y.to_s.split("-")[0] == x
+        y.to_s =~ /^#{x.to_s}(-|$)/
       end
     end.compact.first
   end