X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/8eb77ef5e133e90423ac5048f1e21933d657db01..07211afe3e584167d17b31fc0fde198911abafaa:/app/controllers/amf_controller.rb diff --git a/app/controllers/amf_controller.rb b/app/controllers/amf_controller.rb index 3fa47d088..e29ccf0f4 100644 --- a/app/controllers/amf_controller.rb +++ b/app/controllers/amf_controller.rb @@ -76,7 +76,7 @@ class AmfController < ApplicationController 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)) @@ -213,19 +213,36 @@ class AmfController < ApplicationController # 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 - localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/localised.yaml")) + # first, try the user setting + localised = YAML::load(File.open("#{RAILS_ROOT}/config/potlatch/localised/#{I18n.locale}/localised.yaml")) rescue - localised = "" # guess we'll just have to use the hardcoded English text instead + 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 end begin - help = File.read("#{RAILS_ROOT}/config/potlatch/localised/#{lang}/help.html") + help = File.read("#{RAILS_ROOT}/config/potlatch/localised/#{I18n.locale}/help.html") rescue - help = File.read("#{RAILS_ROOT}/config/potlatch/localised/en/help.html") + 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 end return POTLATCH_PRESETS+[localised,help] end @@ -851,6 +868,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