Permalink
Browse files

Merge pull request #37 from planas/master

Accept available languages as symbols on #sanitize_available_locales
  • Loading branch information...
2 parents b33c8c4 + da6f15e commit c41b3863aac0fae5592eb4e988d5b45f057a2674 @DouweM DouweM committed Feb 5, 2014
Showing with 5 additions and 2 deletions.
  1. +1 −2 lib/http_accept_language/parser.rb
  2. +4 −0 spec/parser_spec.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
@@ -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"

0 comments on commit c41b386

Please sign in to comment.