]> git.openstreetmap.org Git - rails.git/commitdiff
Prefer an exact language match over a prefix match
authorTom Hughes <tom@compton.nu>
Tue, 14 Feb 2012 15:26:01 +0000 (15:26 +0000)
committerTom Hughes <tom@compton.nu>
Tue, 14 Feb 2012 15:26:01 +0000 (15:26 +0000)
vendor/plugins/http_accept_language/lib/http_accept_language.rb

index 1266a3e645560b26bec1f3a7faba4f5479dddf21..0cc8a7719774f00ac836e1370ebac98afe156ab6 100644 (file)
@@ -47,11 +47,10 @@ module HttpAcceptLanguage
   #   request.compatible_language_from I18n.available_locales
   #
   def compatible_language_from(array)
-    user_preferred_languages.map do |x|
-      array.find do |y|
-        y.to_s =~ /^#{Regexp.escape(x.to_s)}(-|$)/
-      end
-    end.compact.first
+    user_preferred_languages.find do |x|
+      array.find { |y| y.to_s == x.to_s } ||
+      array.find { |y| y.to_s =~ /^#{Regexp.escape(x.to_s)}-/ }
+    end
   end
 
 end