diff --git a/lib/rack/contrib/locale.rb b/lib/rack/contrib/locale.rb index 2a1fd91a..d324b17d 100644 --- a/lib/rack/contrib/locale.rb +++ b/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 diff --git a/test/spec_rack_locale.rb b/test/spec_rack_locale.rb index bb16cd4f..a955b374 100644 --- a/test/spec_rack_locale.rb +++ b/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')