Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat locales with variants case insensitively #195

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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