From 899d216b9b2752167f88bb6c204a22345474a3f6 Mon Sep 17 00:00:00 2001 From: DennisSchiefer Date: Sat, 14 Apr 2012 18:03:33 +0200 Subject: [PATCH] made it easier to remove localization and on-demand loading of new language packs, added parameter to say whether to use on-demand reloading, added parameter for the directory that contains the localization files, corrected a small bug when the string for the HEAD_ON instruction was not available, --- WebContent/OSRM.GUI.js | 7 ++- WebContent/OSRM.Geocoder.js | 4 +- WebContent/OSRM.config.js | 4 +- WebContent/localization/OSRM.Locale.de.js | 3 +- WebContent/localization/OSRM.Locale.en.js | 3 +- WebContent/localization/OSRM.Localization.js | 63 ++++++++++--------- WebContent/main.js | 7 +-- WebContent/routing/OSRM.RoutingDescription.js | 2 +- 8 files changed, 50 insertions(+), 43 deletions(-) diff --git a/WebContent/OSRM.GUI.js b/WebContent/OSRM.GUI.js index 675b7f743..6d6389679 100644 --- a/WebContent/OSRM.GUI.js +++ b/WebContent/OSRM.GUI.js @@ -63,11 +63,14 @@ init: function() { document.getElementById('main-wrapper').addEventListener("webkitTransitionEnd", OSRM.GUI.onMainTransitionEnd, false); document.getElementById('main-wrapper').addEventListener("oTransitionEnd", OSRM.GUI.onMainTransitionEnd, false); document.getElementById('main-wrapper').addEventListener("MSTransitionEnd", OSRM.GUI.onMainTransitionEnd, false); - } + } + + // set default language + OSRM.Localization.setLanguage( OSRM.DEFAULTS.LANGUAGE ); }, // set language dependent labels -setLanguage: function() { +setLabels: function() { document.getElementById("open-josm").innerHTML = OSRM.loc("OPEN_JOSM"); document.getElementById("open-osmbugs").innerHTML = OSRM.loc("OPEN_OSMBUGS"); document.getElementById("gui-reset").innerHTML = OSRM.loc("GUI_RESET"); diff --git a/WebContent/OSRM.Geocoder.js b/WebContent/OSRM.Geocoder.js index a1dd6e15c..51eb4bc06 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 + "&accept-language="+OSRM.DEFAULTS.LANGUAGE+"&q=" + query; + var call = OSRM.DEFAULTS.HOST_GEOCODER_URL + "?format=json" + OSRM.DEFAULTS.GEOCODER_BOUNDS + "&accept-language="+OSRM.Localization.current_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} ); }, @@ -155,7 +155,7 @@ updateAddress: function(marker_id, do_fallback_to_lat_lng) { } else return; - var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&accept-language="+OSRM.DEFAULTS.LANGUAGE + "&lat=" + lat + "&lon=" + lng; + var call = OSRM.DEFAULTS.HOST_REVERSE_GEOCODER_URL + "?format=json" + "&accept-language="+OSRM.Localization.current_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/OSRM.config.js b/WebContent/OSRM.config.js index ff5c5ab02..d91e204d4 100644 --- a/WebContent/OSRM.config.js +++ b/WebContent/OSRM.config.js @@ -19,8 +19,7 @@ or see http://www.gnu.org/licenses/agpl.txt. // [has to be loaded directly after OSRM.base] OSRM.DEFAULTS = { - //HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute', - HOST_ROUTING_URL: 'http://141.3.24.68:5000/viaroute', + HOST_ROUTING_URL: 'http://router.project-osrm.org/viaroute', HOST_SHORTENER_URL: 'http://map.project-osrm.org/shorten/', HOST_GEOCODER_URL: 'http://nominatim.openstreetmap.org/search', HOST_REVERSE_GEOCODER_URL: 'http://nominatim.openstreetmap.org/reverse', @@ -33,5 +32,6 @@ OSRM.DEFAULTS = { ONLOAD_TARGET: "", HIGHLIGHT_ZOOM_LEVEL: 16, LANGUAGE: "en", + LANGUAGE_FILES_DIRECTORY: "localization/", GEOCODER_BOUNDS: '&bounded=1&viewbox=-27.0,72.0,46.0,36.0' }; diff --git a/WebContent/localization/OSRM.Locale.de.js b/WebContent/localization/OSRM.Locale.de.js index 40fb9d67e..74bfd35ea 100644 --- a/WebContent/localization/OSRM.Locale.de.js +++ b/WebContent/localization/OSRM.Locale.de.js @@ -84,4 +84,5 @@ OSRM.Localization["de"] = { }; // set GUI language on load -OSRM.Localization.change("de"); \ No newline at end of file +if( OSRM.Localization.use_ondemand_reloading==true) + OSRM.Localization.setLanguage("de"); \ No newline at end of file diff --git a/WebContent/localization/OSRM.Locale.en.js b/WebContent/localization/OSRM.Locale.en.js index b067ee0a4..2bb1d514e 100644 --- a/WebContent/localization/OSRM.Locale.en.js +++ b/WebContent/localization/OSRM.Locale.en.js @@ -84,4 +84,5 @@ OSRM.Localization["en"] = { }; //set GUI language on load -OSRM.Localization.change("en"); \ No newline at end of file +if( OSRM.Localization.use_ondemand_reloading==true) + OSRM.Localization.setLanguage("en"); \ No newline at end of file diff --git a/WebContent/localization/OSRM.Localization.js b/WebContent/localization/OSRM.Localization.js index 1cc098793..ba2240138 100644 --- a/WebContent/localization/OSRM.Localization.js +++ b/WebContent/localization/OSRM.Localization.js @@ -20,10 +20,12 @@ or see http://www.gnu.org/licenses/agpl.txt. OSRM.Localization = { - + +use_ondemand_reloading: true, supported_languages: [ {display_name:"en", encoding:"en"}, {display_name:"de", encoding:"de"} -], +], +current_language: OSRM.DEFAULTS.LANGUAGE, // initialize localization init: function() { @@ -31,8 +33,8 @@ init: function() { var select = document.createElement('select'); select.id = "gui-language-toggle"; select.className = "top-left-button"; - select.onchange = function() { OSRM.Localization.change(this.value); }; - + select.onchange = function() { OSRM.Localization.setLanguage(this.value); }; + // 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 != "" ) { @@ -85,20 +87,25 @@ change: function(language) { document.getElementById('information-box').innerHTML = ""; document.getElementById('information-box-header').innerHTML = ""; } - } else { - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = "localization/OSRM.Locale."+language+".js"; - document.head.appendChild(script); + } else if(OSRM.Localization.use_ondemand_reloading==true) { + for(var i=0, size=OSRM.Localization.supported_languages.length; i English string -> input string translate: function(text) { - if( OSRM.Localization[OSRM.DEFAULTS.LANGUAGE] && OSRM.Localization[OSRM.DEFAULTS.LANGUAGE][text] ) + if( OSRM.Localization[OSRM.Localization.current_language] && OSRM.Localization[OSRM.Localization.current_language][text] ) + return OSRM.Localization[OSRM.Localization.current_language][text]; + else if( OSRM.Localization[OSRM.DEFAULTS.LANGUAGE] && OSRM.Localization[OSRM.DEFAULTS.LANGUAGE][text] ) return OSRM.Localization[OSRM.DEFAULTS.LANGUAGE][text]; - else if( OSRM.Localization["en"] && OSRM.Localization["en"][text] ) - return OSRM.Localization["en"][text]; else return text; } diff --git a/WebContent/main.js b/WebContent/main.js index b1d28c9e2..2c0e81b0f 100644 --- a/WebContent/main.js +++ b/WebContent/main.js @@ -126,12 +126,7 @@ OSRM.parseParameters = function(){ continue; if(name_val[0] == 'hl') { - for(var i=0, size=OSRM.Localization.supported_languages.length; i