]> git.openstreetmap.org Git - rails.git/commitdiff
Make more of the javascript routing functions internationalizable
authorKai Krueger <kakrueger@gmail.com>
Sun, 2 Feb 2014 04:10:54 +0000 (21:10 -0700)
committerKai Krueger <kakrueger@gmail.com>
Sun, 2 Feb 2014 04:10:54 +0000 (21:10 -0700)
app/assets/javascripts/index.js
app/assets/javascripts/routing.js.erb
app/assets/javascripts/routing_engines/cloudmade_foot.js
app/assets/javascripts/routing_engines/graphhopper_bicycle.js
app/assets/javascripts/routing_engines/mapquest_bicycle.js
app/assets/javascripts/routing_engines/osrm_car.js
app/views/layouts/_search.html.erb
config/locales/de.yml
config/locales/en.yml

index d668d6bf7c4989554147284ad7e9dd9c4ef14f2f..8f989deaf84ad40fac9ca0849ce1d3b530661bf7 100644 (file)
@@ -349,7 +349,7 @@ $(document).ready(function () {
   });
 
   OSM.routing = OSM.Routing(map,'OSM.routing',$('.query_wrapper.routing'));
-  OSM.routing.chooseEngine('Car (OSRM)');
+  OSM.routing.chooseEngine('javascripts.directions.engines.osrm_car');
 
   $(".get_directions").on("click",function(e) {
     e.preventDefault();
index b6bf9f4a0cac80fa3f0070f71155d2c1e6802715..3c6db9999888703ea310a0f0b5ef57777cf383ff 100644 (file)
        *** add YOURS engine
 */
 
-var TURN_INSTRUCTIONS=["",
-       "Continue on ",                         // 1
-       "Slight right onto ",           // 2
-       "Turn right onto ",                     // 3
-       "Sharp right onto ",            // 4
-       "U-turn along ",                        // 5
-       "Sharp left onto ",                     // 6
-       "Turn left onto ",                      // 7
-       "Slight left onto ",            // 8
-       "(via point) ",                         // 9
-       "Follow ",                                      // 10
-       "At roundabout take ",          // 11
-       "Leave roundabout - ",          // 12
-       "Stay on roundabout - ",        // 13
-       "Start at end of ",                     // 14
-       "Reach destination",            // 15
-       "Go against one-way on ",       // 16
-       "End of one-way on "]           // 17
+var TURN_INSTRUCTIONS=[]
 
 var ROUTING_POLYLINE={
        color: '#03f',
@@ -48,6 +31,25 @@ OSM.RoutingEngines={
 OSM.Routing=function(map,name,jqSearch) {
        var r={};
 
+    TURN_INSTRUCTIONS=["",
+       I18n.t('javascripts.directions.instructions.continue_on'),                              // 1
+       I18n.t('javascripts.directions.instructions.slight_right'),             // 2
+       I18n.t('javascripts.directions.instructions.turn_right'),                       // 3
+       I18n.t('javascripts.directions.instructions.sharp_right'),              // 4
+       I18n.t('javascripts.directions.instructions.uturn'),                    // 5
+       I18n.t('javascripts.directions.instructions.sharp_left'),                       // 6
+       I18n.t('javascripts.directions.instructions.turn_left'),                        // 7
+       I18n.t('javascripts.directions.instructions.slight_left'),              // 8
+       I18n.t('javascripts.directions.instructions.via_point'),                                // 9
+       I18n.t('javascripts.directions.instructions.follow'),                                   // 10
+       I18n.t('javascripts.directions.instructions.roundabout'),               // 11
+       I18n.t('javascripts.directions.instructions.leave_roundabout'),         // 12
+       I18n.t('javascripts.directions.instructions.stay_roundabout'),  // 13
+       I18n.t('javascripts.directions.instructions.start'),                    // 14
+       I18n.t('javascripts.directions.instructions.destination'),              // 15
+       I18n.t('javascripts.directions.instructions.against_oneway'),   // 16
+       I18n.t('javascripts.directions.instructions.end_oneway')]               // 17
+
        r.map=map;                              // Leaflet map
        r.name=name;                    // global variable name of this instance (needed for JSONP)
        r.jqSearch=jqSearch;    // JQuery object for search panel
@@ -184,7 +186,7 @@ OSM.Routing=function(map,name,jqSearch) {
                // Create base table
                $("#content").removeClass("overlay-sidebar");
                $('#sidebar_content').empty();
-               var html='<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;"><span class="icon close"></span></a>Directions</h2>'.replace(/~/g,"'");
+               var html='<h2><a class="geolink" href="#" onclick="$(~.close_directions~).click();return false;"><span class="icon close"></span></a>' + I18n.t('javascripts.directions.directions') + '</h2>'.replace(/~/g,"'");
                html+="<table id='turnbyturn' />";
                $('#sidebar_content').html(html);
                // Add each row
@@ -242,7 +244,7 @@ OSM.Routing=function(map,name,jqSearch) {
                        };
                        r['gotRoute'+num]=function(data) { r.awaitingRoute=false; list[num].gotRoute(r,data); };
                }
-               select.append("<option value='"+i+"'>"+list[i].name+"</option>");
+               select.append("<option value='"+i+"'>"+I18n.t(list[i].name)+"</option>");
        }
        r.engines=list;
        r.chosenEngine=list[0]; // default to first engine
index 5193c647245067b5a51dca4f62bf476b7d6bcc57..5c1ba0e9716ab1088042640fab5f7470230a7a90 100644 (file)
@@ -4,7 +4,7 @@
 // http://cloudmade.com/documentation/routing
 
 OSM.RoutingEngines.list.push({
-       name: 'Foot (CloudMade)',
+       name: "javascripts.directions.engines.cloudmade_foot",
        draggable: false,
        CM_SPRITE_MAP: {
                "C": 1,
@@ -25,7 +25,8 @@ OSM.RoutingEngines.list.push({
                }
                url+=p.join(',');
                url+="/foot.js";
-               this.requestJSONP(url+"?callback=");
+        url+="?lang=" + I18n.currentLocale();
+               this.requestJSONP(url+"&callback=");
        },
        gotRoute: function(router,data) {
                router.setPolyline(data.route_geometry);
index 7f7c83c80116c44a16a95e17a5d086a721bf03a0..6245124b1cd1ea5349027aac9e94195c719b3cb3 100644 (file)
@@ -1,11 +1,11 @@
 // GraphHopper bicycle engine
 
 OSM.RoutingEngines.list.push({    
-    name: 'Bicycle (GraphHopper)',
+    name: "javascripts.directions.engines.graphhopper_bike",
     draggable: true,
     _hints: {},
     getRoute: function(isFinal, points) {
-        var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=en";
+        var url = "http://graphhopper.com/routing/api/route?vehicle=bike&locale=" + I18n.currentLocale();
         for (var i = 0; i < points.length; i++) {
             var pair = points[i].join(',');
             url += "&point=" + pair;
index f74ccba151951c9032b5be80ea9c4dd7a8daec60..b080969558400c03fd2d012a7d86b0697d65daed 100644 (file)
@@ -6,7 +6,7 @@
 // *** needs to give credit
 
 OSM.RoutingEngines.list.push({
-       name: 'Bicycle (MapQuest Open)',
+       name: "javascripts.directions.engines.mapquest_bike",
        draggable: false,
        _hints: {},
        MQ_SPRITE_MAP: {
@@ -36,6 +36,7 @@ OSM.RoutingEngines.list.push({
                url+="&from="+from.join(',');
                url+="&to="+to.join(',');
                url+="&routeType=bicycle";
+        //url+="&locale=" + I18n.currentLocale(); //Doesn't actually work. MapQuest requires full locale e.g. "de_DE", but I18n only provides language, e.g. "de"
                url+="&manMaps=false";
                url+="&shapeFormat=raw&generalize=0";
                this.requestJSONP(url+"&callback=");
index cb80c5615ba3d7fd2e23a5f59aba707c11197a5f..0011b02058167d33ed4fdce606e09418a6d81a2b 100644 (file)
@@ -3,7 +3,7 @@
 // *** need to clear hints at some point
 
 OSM.RoutingEngines.list.push({
-       name: 'Car (OSRM)',
+       name: "javascripts.directions.engines.osrm_car",
        draggable: true,
        _hints: {},
        getRoute: function(isFinal,points) {
@@ -34,7 +34,7 @@ OSM.RoutingEngines.list.push({
                        var instText="<b>"+(i+1)+".</b> ";
                        instText+=TURN_INSTRUCTIONS[instCodes[0]];
                        if (instCodes[1]) { instText+="exit "+instCodes[1]+" "; }
-                       if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : "(unnamed)"; }
+                       if (instCodes[0]!=15) { instText+=s[1] ? "<b>"+s[1]+"</b>" : I18n.t('javascripts.directions.instructions.unnamed'); }
                        steps.push([line[s[3]], s[0].split('-')[0], instText, s[2]]);
                }
                if (steps.length) router.setItinerary({ steps: steps });
index e1c85f3b7b1dd3b9a412bd2e56ad36da8d30cec9..e9aa76f5a47c89bce57741c105c5ab96b837859c 100644 (file)
@@ -16,9 +16,9 @@
 
   <div class='query_wrapper routing'>
     <%= image_tag "marker-green.png", :class => 'routing_marker', :id => 'marker_from', :draggable => 'true' %>
-    <%= text_field_tag "route_from", params[:from], :placeholder => "From", :onchange=>"OSM.routing.geocode('route_from',event)" %>
+    <%= text_field_tag "route_from", params[:from], :placeholder => t('site.search.from'), :onchange=>"OSM.routing.geocode('route_from',event)" %>
     <%= image_tag "marker-red.png"  , :class => 'routing_marker', :id => 'marker_to'  , :draggable => 'true' %>
-    <%= text_field_tag "route_to"  , params[:to]  , :placeholder => "To"  , :onchange=>"OSM.routing.geocode('route_to'  ,event)" %>
+    <%= text_field_tag "route_to"  , params[:to]  , :placeholder => t('site.search.to')  , :onchange=>"OSM.routing.geocode('route_to'  ,event)" %>
     <select class='routing_engines' name='routing_engines' onchange="OSM.routing.selectEngine(event)"></select>
   </div>
 
index 7d5cfc60ea1522849d8b8b7c28e92f32a8063a25..16bdfbe1a8d8ff0dfc741467dc48cba715c3eab0 100644 (file)
@@ -929,6 +929,32 @@ de:
   javascripts: 
     close: Schließen
     edit_help: Wähle eine höhere Zoomstufe und verschiebe die Karte an einen Ort, den du bearbeiten möchtest, und klicke hier.
+    directions:
+      directions: "Fahranweisungen: "
+      engines:
+        graphhopper_bike: "Fahrrad (GraphHopper)"
+        mapquest_bike: "Fahrrad (MapQuest)"
+        osrm_car: "Auto (OSRM)"
+        cloudmade_foot: "Fuss (Cloudmade)"
+      instructions:
+        continue_on: "Weiter auf "
+        slight_right: "Rechts halten auf "
+        turn_right: "Rechts abbiegen auf "
+        sharp_right: "Hart rechts auf "
+        uturn: "U-turn along "
+        sharp_left: "Hart links auf "
+        turn_left: "Links abbiegen auf "
+        slight_left: "Links halten auf "
+        via_point: "(via point) "
+        follow:  "Folge "
+        roundabout: "Im Kreisverkehr nehme "
+        leave_roundabout: "Verlasse den Kreisverkehr - "
+        stay_roundabout: "Stay on roundabout - "
+        start: "Start at end of "
+        destination: "Ziel erreicht"
+        against_oneway: "Go against one-way on "
+        end_oneway: "Ende der Einbahnstrasse "
+        unnamed: "(unbekannt)"
     key: 
       title: Legende
       tooltip: Legende
@@ -1467,6 +1493,12 @@ de:
       preview: Vorschau
     search: 
       search: Suchen
+      get_directions: "Route berechnen"
+      get_directions_title: "Routenberechnung zwischen zwei Orten"
+      close_directions: "Schliessen der Route"
+      close_directions_title: "Schliessen des Routenmenus"
+      from: "Von"
+      to: "Nach"
       submit_text: Los
       where_am_i: Wo bin ich?
       where_am_i_title: Die momentane Position mit der Suchmaschine anzeigen
index 4bc926f2bc994135f4bb0cc7f66bd80d20b4274f..e567a497de9f2222c1c1f7822f39702cdc99ae2a 100644 (file)
@@ -1328,6 +1328,8 @@ en:
       get_directions_title: "Find directions between two points"
       close_directions: "Close directions"
       close_directions_title: "Close the directions panel"
+      from: "From"
+      to: "To"
       where_am_i: "Where am I?"
       where_am_i_title: Describe the current location using the search engine
       submit_text: "Go"
@@ -2116,6 +2118,32 @@ en:
         comment_and_resolve: Comment & Resolve
         comment: Comment
     edit_help: Move the map and zoom in on a location you want to edit, then click here.
+    directions:
+      engines:
+        graphhopper_bike: "Bicycle (GraphHopper)"
+        mapquest_bike: "Bicycle (MapQuest)"
+        osrm_car: "Car (OSRM)"
+        cloudmade_foot: "Foot (Cloudmade)"
+      directions: "Directions"
+      instructions:
+        continue_on: "Continue on "
+        slight_right: "Slight right onto "
+        turn_right: "Turn right onto "
+        sharp_right: "Sharp right onto "
+        uturn: "U-turn along "
+        sharp_left: "Sharp left onto "
+        turn_left: "Turn leeeeft onto "
+        slight_left: "Slight left onto "
+        via_point: "(via point) "
+        follow:  "Follow "
+        roundabout: "At roundabout take "
+        leave_roundabout: "Leave roundabout - "
+        stay_roundabout: "Stay on roundabout - "
+        start: "Start at end of "
+        destination: "Reach destination"
+        against_oneway: "Go against one-way on "
+        end_oneway: "End of one-way on "
+        unnamed: "(unnamed)"
   redaction:
     edit:
       description: "Description"