Skip to content

Commit 96de0b1

Browse files
authored
Treat locales with variants case insenitively (#195)
1 parent d5265bc commit 96de0b1

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/rack/contrib/locale.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def user_preferred_locale(header)
7575
matched_locale = I18n.available_locales.find { |al| match?(al, locale) } if locale
7676
if !locale && !matched_locale
7777
matched_locale = locales.reverse.find { |locale| I18n.available_locales.any? { |al| variant_match?(al, locale) } }
78-
matched_locale = matched_locale[0,2] if matched_locale
78+
matched_locale = matched_locale[0,2].downcase if matched_locale
7979
end
8080
matched_locale
8181
else

test/spec_rack_locale.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ def enforce_available_locales(enforce)
7575
_(response_with_languages('pt;Q=0.9,es-CL').body).must_equal('es')
7676
end
7777

78+
specify 'should match languages with variants case insensitively' do
79+
_(response_with_languages('pt;Q=0.9,ES-CL').body).must_equal('es')
80+
end
81+
7882
specify 'should skip * if it is followed by other languages' do
7983
_(response_with_languages('*,dk;q=0.5').body).must_equal('dk')
8084
end

0 commit comments

Comments
 (0)