From ea207cef6e6634a06f88532fd84dce8ef02b3b50 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Tue, 10 Apr 2012 21:47:30 +0200 Subject: [PATCH] improved language support: geocoding uses language settings, geocoding results & locations are also translated if possible --- WebContent/OSRM.GUI.js | 7 ++++--- WebContent/OSRM.Geocoder.js | 4 ++-- WebContent/localization/OSRM.Localization.js | 21 +++++++++++++++----- WebContent/main.html | 2 +- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/WebContent/OSRM.GUI.js b/WebContent/OSRM.GUI.js index 797b482eb..f60b44913 100644 --- a/WebContent/OSRM.GUI.js +++ b/WebContent/OSRM.GUI.js @@ -30,6 +30,10 @@ init: function() { OSRM.GUI.visible = true; OSRM.GUI.width = document.getElementById("main-wrapper").clientWidth; + // init starting source/target + document.getElementById('gui-input-source').value = OSRM.DEFAULTS.ONLOAD_SOURCE; + document.getElementById('gui-input-target').value = OSRM.DEFAULTS.ONLOAD_TARGET; + // init events // [TODO: switch to new event model] document.getElementById("gui-toggle-in").onclick = OSRM.GUI.toggleMain; @@ -77,9 +81,6 @@ setLanguage: function() { document.getElementById("gui-input-source").title = OSRM.loc("GUI_START_TOOLTIP"); document.getElementById("gui-input-target").title = OSRM.loc("GUI_END_TOOLTIP"); document.getElementById("legal-notice").innerHTML = OSRM.loc("GUI_LEGAL_NOTICE"); - - document.getElementById('gui-input-source').value = OSRM.DEFAULTS.ONLOAD_SOURCE; - document.getElementById('gui-input-target').value = OSRM.DEFAULTS.ONLOAD_TARGET; }, // show/hide main-gui diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/OSRM.Geocoder.js index 4331b3e9a..d02029e51 100644 --- a/WebContent/OSRM.Geocoder.js +++ b/WebContent/OSRM.Geocoder.js @@ -43,7 +43,7 @@ call: function(marker_id, query) { } //build request for geocoder - var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&q=" + query; + var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.DEFAULTS.LANGUAGE+"&q=" + query; OSRM.JSONP.call( call, OSRM.Geocoder._showResults, OSRM.Geocoder._showResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "geocoder_"+marker_id, {marker_id:marker_id,query:query} ); }, @@ -154,7 +154,7 @@ updateAddress: function(marker_id, do_fallback_to_lat_lng) { } else return; - var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&lat=" + lat + "&lon=" + lng; + var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&accept-language="+OSRM.DEFAULTS.LANGUAGE + "&lat=" + lat + "&lon=" + lng; OSRM.JSONP.call( call, OSRM.Geocoder._showReverseResults, OSRM.Geocoder._showReverseResults_Timeout, OSRM.DEFAULTS.JSONP_TIMEOUT, "reverse_geocoder_"+marker_id, {marker_id:marker_id, do_fallback: do_fallback_to_lat_lng} ); }, diff --git a/WebContent/localization/OSRM.Localization.js b/WebContent/localization/OSRM.Localization.js index ec3278771..4063a619b 100644 --- a/WebContent/localization/OSRM.Localization.js +++ b/WebContent/localization/OSRM.Localization.js @@ -21,7 +21,9 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.Localization = { -supported_languages: ["en", "de"], +supported_languages: [ {display_name:"en", encoding:"en"}, + {display_name:"de", encoding:"de"} +], // initialize localization init: function() { @@ -33,8 +35,8 @@ init: function() { // fill dropdown menu for(var i=0, size=OSRM.Localization.supported_languages.length; i 1) + OSRM.Routing.getRoute(); + else if(OSRM.G.markers.route.length > 0 && document.getElementById('information-box').innerHTML != "" ) { + OSRM.Geocoder.call( OSRM.C.SOURCE_LABEL, document.getElementById("gui-input-source").value ); + OSRM.Geocoder.call( OSRM.C.TARGET_LABEL, document.getElementById("gui-input-target").value ); + } else { + OSRM.Geocoder.updateAddress(OSRM.C.SOURCE_LABEL, false); + OSRM.Geocoder.updateAddress(OSRM.C.TARGET_LABEL, false); + document.getElementById('information-box').innerHTML = ""; + document.getElementById('information-box-header').innerHTML = ""; + } } else { var script = document.createElement('script'); script.type = 'text/javascript'; diff --git a/WebContent/main.html b/WebContent/main.html index 171fc9da3..271f73d46 100644 --- a/WebContent/main.html +++ b/WebContent/main.html @@ -71,7 +71,7 @@ or see http://www.gnu.org/licenses/agpl.txt. - +