]> git.openstreetmap.org Git - rails.git/commitdiff
Don't fall back to name:en if it's not in the user's language list
authorTom Hughes <tom@compton.nu>
Thu, 6 Aug 2020 13:21:30 +0000 (14:21 +0100)
committerTom Hughes <tom@compton.nu>
Thu, 6 Aug 2020 13:21:30 +0000 (14:21 +0100)
Fix to #2755

app/helpers/browse_helper.rb
lib/locale.rb

index cf2bc64742dc6faebb72e511a7c9ebb958b537e2..4519567d2b7f8f7af1c81b8cd3b5f4704576f9cf 100644 (file)
@@ -13,7 +13,7 @@ module BrowseHelper
     unless object.redacted?
       available_locales = Locale.list(name_locales(object))
 
-      locale = available_locales.preferred(preferred_languages)
+      locale = available_locales.preferred(preferred_languages, :default => nil)
 
       if object.tags.include? "name:#{locale}"
         name = t "printable_name.with_name_html", :name => tag.bdi(object.tags["name:#{locale}"].to_s), :id => tag.bdi(name)
index b0ad20fc793f4bd4332057af1002c38a39e3cfdd..56d3985760f8447455bcf93f7dd181fd949d60a3 100644 (file)
@@ -10,8 +10,8 @@ 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
@@ -19,7 +19,7 @@ class Locale < I18n::Locale::Tag::Rfc4646
                  locale.candidates.uniq.reverse_each do |candidate|
                    expanded << candidate if candidate == locale || !expanded.include?(candidate)
                  end
-               end.reverse.uniq << Locale.default)
+               end.reverse.uniq)
     end
   end