Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Accept available languages as symbols on #sanitize_available_locales

  • Loading branch information...
commit da6f15e81d6b62c3c721ac11d4e4492181d8edc1 1 parent b33c8c4
@planas planas authored
Showing with 5 additions and 2 deletions.
  1. +1 −2  lib/http_accept_language/parser.rb
  2. +4 −0 spec/parser_spec.rb
View
3  lib/http_accept_language/parser.rb
@@ -73,7 +73,7 @@ def compatible_language_from(available_languages)
#
def sanitize_available_locales(available_languages)
available_languages.map do |available|
- available.split(/[_-]/).reject { |part| part.start_with?("x") }.join("-")
+ available.to_s.split(/[_-]/).reject { |part| part.start_with?("x") }.join("-")
end
end
@@ -90,7 +90,6 @@ def language_region_compatible_from(available_languages)
available_languages = sanitize_available_locales(available_languages)
user_preferred_languages.map do |preferred| #en-US
lang_group = available_languages.select do |available| # en
- available = available.to_s
preferred.split('-', 2).first == available.split('-', 2).first
end
lang_group.find { |lang| lang == preferred } || lang_group.first #en-US, en-UK
View
4 spec/parser_spec.rb
@@ -48,6 +48,10 @@ def parser
parser.sanitize_available_locales(%w{en_UK-x3 en-US-x1 ja_JP-x2 pt-BR-x5 es-419-x4}).should eq ["en-UK", "en-US", "ja-JP", "pt-BR", "es-419"]
end
+ it "should accept available language names as symbols and return them as strings" do
+ parser.sanitize_available_locales([:en, :"en-US", :ca, :"ca-ES"]).should eq ["en", "en-US", "ca", "ca-ES"]
+ end
+
it "should find most compatible language from user preferred" do
parser.header = 'ja,en-gb,en-us,fr-fr'
parser.language_region_compatible_from(%w{en-UK en-US ja-JP}).should eq "ja-JP"
Please sign in to comment.
Something went wrong with that request. Please try again.