Skip to content

Commit

Permalink
Make compatible_language_from follow the RFC 2616 selection algorithm
Browse files Browse the repository at this point in the history
We need to look for the longest matching prefix rather than just the
first language with the same basic language code, otherwise if we have
both zh-CN and zh-TW available then we may select the wrong one as we
will return he first one we see that starts with zh even if the user
had said they preferred a specific variant.
  • Loading branch information
tomhughes authored and iain committed May 24, 2010
1 parent 33f9685 commit a24a364
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/http_accept_language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ def preferred_language_from(array)
#
def compatible_language_from(array)
user_preferred_languages.map do |x|
x = x.to_s.split("-")[0]
array.find do |y|
y.to_s.split("-")[0] == x
y.to_s =~ /^#{Regexp.escape(x.to_s)}(-|$)/
end
end.compact.first
end
Expand Down

0 comments on commit a24a364

Please sign in to comment.