]> git.openstreetmap.org Git - rails.git/blobdiff - lib/locale.rb
Merge remote-tracking branch 'upstream/pull/4776'
[rails.git] / lib / locale.rb
index b0ad20fc793f4bd4332057af1002c38a39e3cfdd..5931301b5af6bf46f3291aa1b86418226b6b6857 100644 (file)
@@ -10,16 +10,16 @@ class Locale < I18n::Locale::Tag::Rfc4646
       preferred.expand & self
     end
 
-    def preferred(preferred)
-      candidates(preferred).first
+    def preferred(preferred, options = { :default => Locale.default })
+      candidates(preferred).first || options[:default]
     end
 
     def expand
       List.new(reverse.each_with_object([]) do |locale, expanded|
                  locale.candidates.uniq.reverse_each do |candidate|
-                   expanded << candidate if candidate == locale || !expanded.include?(candidate)
+                   expanded << candidate if candidate == locale || expanded.exclude?(candidate)
                  end
-               end.reverse.uniq << Locale.default)
+               end.reverse.uniq)
     end
   end