Permalink
Browse files

* fixed code so that tests are green again

* added symbol support for available languages
  • Loading branch information...
1 parent 5d055e0 commit 92b276c92db8dae14c51169d6567c2f7a2563141 Norman/Thies committed with iain Jun 25, 2010
Showing with 10 additions and 4 deletions.
  1. +5 −4 lib/http_accept_language.rb
  2. +5 −0 test/http_accept_language_test.rb
@@ -46,10 +46,11 @@ def preferred_language_from(array)
#
# 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)}(-|$)/
+ def compatible_language_from(available_languages)
+ user_preferred_languages.map do |x| #en-US
+ available_languages.find do |y| # en
+ y = y.to_s
+ x == y || x.split('-', 2).first == y.split('-', 2).first
end
end.compact.first
end
@@ -37,6 +37,11 @@ def test_should_find_first_compatible_from_user_preferred
request.env['HTTP_ACCEPT_LANGUAGE'] = 'en-us,de-de'
assert_equal 'en', request.compatible_language_from(%w{de en})
end
+
+ def test_should_accept_symbols_as_available_languages
+ request.env['HTTP_ACCEPT_LANGUAGE'] = 'en-us'
+ assert_equal :"en-HK", request.compatible_language_from([:"en-HK"])
+ end
private
def request

0 comments on commit 92b276c

Please sign in to comment.