From 25d0017b18773458529275d2f60f2599ee03a633 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Wed, 15 Jul 2009 23:42:56 +0000 Subject: [PATCH] Fix compatible_language_from in the http_accept_language plugin to correctly follow the RFC 2616 language selection algorithm and then revert to the previous way of selecting languages. --- app/controllers/application_controller.rb | 5 ++--- .../plugins/http_accept_language/lib/http_accept_language.rb | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 00104b0a1..0d6cdea64 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/vendor/plugins/http_accept_language/lib/http_accept_language.rb b/vendor/plugins/http_accept_language/lib/http_accept_language.rb index 85ee89c95..1bedd6c74 100644 --- a/vendor/plugins/http_accept_language/lib/http_accept_language.rb +++ b/vendor/plugins/http_accept_language/lib/http_accept_language.rb @@ -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 -- 2.39.5