Skip to content

Commit

Permalink
Rack::Locale: support "*" langague
Browse files Browse the repository at this point in the history
  • Loading branch information
James A. Rosen committed Aug 19, 2012
1 parent a790c26 commit be2193b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/rack/contrib/locale.rb
Expand Up @@ -30,9 +30,9 @@ def accept_locale(env)


lang = languages_and_qvalues.sort_by { |(locale, qvalue)| lang = languages_and_qvalues.sort_by { |(locale, qvalue)|
qvalue.to_f qvalue.to_f
}.last }.last.first


lang.first lang == '*' ? nil : lang
end end
end end
end end
4 changes: 4 additions & 0 deletions test/spec_rack_locale.rb
Expand Up @@ -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') response_with_languages('en-gb,en-us;q=0.95;en').body.should.equal('en-gb')
end 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 specify 'should reset the I18n locale after the response' do
I18n.locale = 'es' I18n.locale = 'es'
response_with_languages('en,de;q=0.8') response_with_languages('en,de;q=0.8')
Expand Down

0 comments on commit be2193b

Please sign in to comment.