Improve formatting of OSRM directions
authorTom Hughes <tom@compton.nu>
Wed, 1 Jul 2015 20:03:54 +0000 (21:03 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 1 Jul 2015 20:03:54 +0000 (21:03 +0100)
Fixes #904

app/assets/javascripts/index/directions/osrm.js
config/locales/en.yml

index 2156bf309252c4e1fa50c3f0e657e0fe8e71bcf1..5c1ce6906e2c1513ff1a49422c527439d66f4fa9 100644 (file)
@@ -12,23 +12,23 @@ function OSRMEngine() {
     getRoute: function (points, callback) {
       var 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
+        'javascripts.directions.instructions.continue_on',      // 1
+        'javascripts.directions.instructions.slight_right',     // 2
+        'javascripts.directions.instructions.turn_right',       // 3
+        'javascripts.directions.instructions.sharp_right',      // 4
+        'javascripts.directions.instructions.uturn',            // 5
+        'javascripts.directions.instructions.sharp_left',       // 6
+        'javascripts.directions.instructions.turn_left',        // 7
+        'javascripts.directions.instructions.slight_left',      // 8
+        'javascripts.directions.instructions.via_point',        // 9
+        'javascripts.directions.instructions.follow',           // 10
+        'javascripts.directions.instructions.roundabout',       // 11
+        'javascripts.directions.instructions.leave_roundabout', // 12
+        'javascripts.directions.instructions.stay_roundabout',  // 13
+        'javascripts.directions.instructions.start',            // 14
+        'javascripts.directions.instructions.destination',      // 15
+        'javascripts.directions.instructions.against_oneway',   // 16
+        'javascripts.directions.instructions.end_oneway'        // 17
       ];
 
       var url = document.location.protocol + "//router.project-osrm.org/viaroute?z=14&output=json&instructions=true";
@@ -64,13 +64,11 @@ function OSRMEngine() {
             var linesegend;
             var instCodes = s[0].split('-');
             var instText = "<b>" + (i + 1) + ".</b> ";
-            instText += TURN_INSTRUCTIONS[instCodes[0]];
-            if (instCodes[1]) {
-              instText += I18n.t('javascripts.directions.instructions.exit', { exit: instCodes[1] } );
-            }
-            if (instCodes[0] !== 15) {
-              instText += " ";
-              instText += s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
+            var name = s[1] ? "<b>" + s[1] + "</b>" : I18n.t('javascripts.directions.instructions.unnamed');
+            if (instCodes[0] === "11" && instCodes[1]) {
+              instText += I18n.t('javascripts.directions.instructions.roundabout_with_exit', { exit: instCodes[1], name: name } );
+            } else {
+              instText += I18n.t(TURN_INSTRUCTIONS[instCodes[0]], { name: name });
             }
             if ((i + 1) < data.route_instructions.length) {
               linesegend = data.route_instructions[i + 1][3] + 1;
index daab37f434a60fb481c71391979599a7af866065..ffb22bd6013de0513ba0025bcf40dcf81f60d7ca 100644 (file)
@@ -2241,25 +2241,25 @@ en:
         no_route: "Couldn't find a route between those two places."
         no_place: "Sorry - couldn't find that place."
       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 left onto
-        slight_left: Slight left onto
+        continue_on: Continue on %{name}
+        slight_right: Slight right onto %{name}
+        turn_right: Turn right onto %{name}
+        sharp_right: Sharp right onto %{name}
+        uturn: U-turn along %{name}
+        sharp_left: Sharp left onto %{name}
+        turn_left: Turn left onto %{name}
+        slight_left: Slight left onto %{name}
         via_point: (via point)
-        follow: Follow
-        roundabout: At roundabout take
-        leave_roundabout: Leave roundabout -
-        stay_roundabout: Stay on roundabout -
-        start: Start at end of
+        follow: Follow %{name}
+        roundabout: At roundabout take %{name}
+        leave_roundabout: Leave roundabout - %{name}
+        stay_roundabout: Stay on roundabout - %{name}
+        start: Start at end of %{name}
         destination: Reach destination
-        against_oneway: Go against one-way on
-        end_oneway: End of one-way on
-        exit: exit %{exit}
-        unnamed: "(unnamed)"
+        against_oneway: Go against one-way on %{name}
+        end_oneway: End of one-way on %{name}
+        roundabout_with_exit: At roundabout take exit %{exit} onto %{name}
+        unnamed: "unnamed road"
         courtesy: "Directions courtesy of %{link}"
       time: "Time"
     query: