]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/amf_controller.rb
changed component name in trac
[rails.git] / app / controllers / amf_controller.rb
index 5a8ac49c36234128f0a70553805a883e68f9fd04..2aee84d0cf0bf475735d8564bf18ddfc43324c9f 100644 (file)
@@ -214,27 +214,26 @@ class AmfController < ApplicationController
   # uses POTLATCH_PRESETS global, set up in OSM::Potlatch.
 
   def getpresets(usertoken,lang) #:doc:
+    user = getuser(usertoken)
+
+    if user && !user.languages.empty?
+      request.user_preferred_languages = user.languages
+    end
+
+    lang = request.compatible_language_from(getlocales)
+
     begin
-      # first, try the user setting
-      localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{I18n.locale}/localised.yaml"))
+      # if not, try the browser language
+      localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/localised.yaml"))
     rescue
-      begin
-        # if not, try the browser language
-        localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/localised.yaml"))
-      rescue
-        # fall back to hardcoded English text
-        localised = ""
-      end
+      # fall back to hardcoded English text
+      localised = ""
     end
 
     begin
-      help = File.read("#{RAILS_ROOT}/config/potlatch/localised/#{I18n.locale}/help.html")
+      help = File.read("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/help.html")
     rescue
-      begin
-        help = File.read("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/help.html")
-      rescue
-        help = File.read("#{RAILS_ROOT}/config/potlatch/localised/en/help.html")
-      end
+      help = File.read("#{RAILS_ROOT}/config/potlatch/localised/en/help.html")
     end
     return POTLATCH_PRESETS+[localised,help]
   end
@@ -860,6 +859,9 @@ class AmfController < ApplicationController
     }
   end
 
+  def getlocales
+    Dir.glob("#{RAILS_ROOT}/config/potlatch/localised/*").collect { |f| File.basename(f) }
+  end
 
   # ====================================================================
   # Alternative SQL queries for getway/whichways