]> 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 3fa47d0881dbe9e5894079a9c771d3f0e0919ec2..2aee84d0cf0bf475735d8564bf18ddfc43324c9f 100644 (file)
@@ -76,7 +76,7 @@ class AmfController < ApplicationController
         logger.info("Executing AMF #{message}(#{args.join(',')}):#{index}")
 
         case message
         logger.info("Executing AMF #{message}(#{args.join(',')}):#{index}")
 
         case message
-          when 'getpresets';        results[index]=AMF.putdata(index,getpresets(args[0]))
+          when 'getpresets';        results[index]=AMF.putdata(index,getpresets(*args))
           when 'whichways';         results[index]=AMF.putdata(index,whichways(*args))
           when 'whichways_deleted'; results[index]=AMF.putdata(index,whichways_deleted(*args))
           when 'getway';            results[index]=AMF.putdata(index,getway(args[0].to_i))
           when 'whichways';         results[index]=AMF.putdata(index,whichways(*args))
           when 'whichways_deleted'; results[index]=AMF.putdata(index,whichways_deleted(*args))
           when 'getway';            results[index]=AMF.putdata(index,getway(args[0].to_i))
@@ -213,13 +213,21 @@ class AmfController < ApplicationController
   # Return presets (default tags, localisation etc.):
   # uses POTLATCH_PRESETS global, set up in OSM::Potlatch.
 
   # Return presets (default tags, localisation etc.):
   # uses POTLATCH_PRESETS global, set up in OSM::Potlatch.
 
-  def getpresets(lang) #:doc:
-    lang.gsub!(/[^\w\-]/,'')
+  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
 
     begin
+      # if not, try the browser language
       localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/localised.yaml"))
     rescue
       localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/localised.yaml"))
     rescue
-      localised = "" # guess we'll just have to use the hardcoded English text instead
+      # fall back to hardcoded English text
+      localised = ""
     end
 
     begin
     end
 
     begin
@@ -851,6 +859,9 @@ class AmfController < ApplicationController
     }
   end
 
     }
   end
 
+  def getlocales
+    Dir.glob("#{RAILS_ROOT}/config/potlatch/localised/*").collect { |f| File.basename(f) }
+  end
 
   # ====================================================================
   # Alternative SQL queries for getway/whichways
 
   # ====================================================================
   # Alternative SQL queries for getway/whichways