Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Rack::Locale: support "*" langague

  • Loading branch information...
commit be2193bd8730248f90c66cef31a28f39846b57aa 1 parent a790c26
James A. Rosen authored
Showing with 6 additions and 2 deletions.
  1. +2 −2 lib/rack/contrib/locale.rb
  2. +4 −0 test/spec_rack_locale.rb
View
4 lib/rack/contrib/locale.rb
@@ -30,9 +30,9 @@ def accept_locale(env)
lang = languages_and_qvalues.sort_by { |(locale, qvalue)|
qvalue.to_f
- }.last
+ }.last.first
- lang.first
+ lang == '*' ? nil : lang
end
end
end
View
4 test/spec_rack_locale.rb
@@ -44,6 +44,10 @@ def response_with_languages(accept_languages)
response_with_languages('en-gb,en-us;q=0.95;en').body.should.equal('en-gb')
end
+ specify 'should treat a * as "all other languages"' do
+ response_with_languages('*,en;q=0.5').body.should.equal( I18n.default_locale.to_s )
+ end
+
specify 'should reset the I18n locale after the response' do
I18n.locale = 'es'
response_with_languages('en,de;q=0.8')
Please sign in to comment.
Something went wrong with that request. Please try again.