Skip to content

Commit

Permalink
Treat locales with variants case insenitively (#195)
Browse files Browse the repository at this point in the history
  • Loading branch information
nampas authored Oct 30, 2024
1 parent d5265bc commit 96de0b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rack/contrib/locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def user_preferred_locale(header)
matched_locale = I18n.available_locales.find { |al| match?(al, locale) } if locale
if !locale && !matched_locale
matched_locale = locales.reverse.find { |locale| I18n.available_locales.any? { |al| variant_match?(al, locale) } }
matched_locale = matched_locale[0,2] if matched_locale
matched_locale = matched_locale[0,2].downcase if matched_locale
end
matched_locale
else
Expand Down
4 changes: 4 additions & 0 deletions test/spec_rack_locale.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ def enforce_available_locales(enforce)
_(response_with_languages('pt;Q=0.9,es-CL').body).must_equal('es')
end

specify 'should match languages with variants case insensitively' do
_(response_with_languages('pt;Q=0.9,ES-CL').body).must_equal('es')
end

specify 'should skip * if it is followed by other languages' do
_(response_with_languages('*,dk;q=0.5').body).must_equal('dk')
end
Expand Down

0 comments on commit 96de0b1

Please sign in to comment.