-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add waypoint arrival instruction #111
Conversation
Note, I had to add a metadata field to the fixture files to configure each compile test to allow for unique legIndex values in d0f94ad |
index.js
Outdated
@@ -68,7 +68,7 @@ module.exports = function(version, _options) { | |||
|
|||
return config.join(''); | |||
}, | |||
compile: function(language, step) { | |||
compile: function(language, step, legIndex) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New optional third argument, legIndex.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would you indicate “final”? −1? (We would also need to add a string for “final” to the translations.)
index.js
Outdated
@@ -173,7 +172,7 @@ module.exports = function(version, _options) { | |||
.replace('{lane_instruction}', laneInstruction) | |||
.replace('{modifier}', instructions[language][version].constants.modifier[modifier]) | |||
.replace('{direction}', this.directionFromDegree(language, step.maneuver.bearing_after)) | |||
.replace('{nth}', nthWaypoint) | |||
.replace('{nth}', legIndex && legIndex > 0 ? this.ordinalize(language, legIndex) : '') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this logic, if there are multiple destinations, the first destination is announced as, “You have arrived at your destination.”
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it may be necessary to accept yet another parameter, the leg count. (That way we also don’t need to represent the last step index as −1.)
index.js
Outdated
@@ -173,7 +175,7 @@ module.exports = function(version, _options) { | |||
.replace('{lane_instruction}', laneInstruction) | |||
.replace('{modifier}', instructions[language][version].constants.modifier[modifier]) | |||
.replace('{direction}', this.directionFromDegree(language, step.maneuver.bearing_after)) | |||
.replace('{nth}', nthWaypoint) | |||
.replace('{nth}', waypoint) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nthWaypoint was a more descriptive name. We aren't dealing with the waypoint itself; we're dealing with an ordinal word representing the one-based leg "index".
index.js
Outdated
@@ -162,9 +163,10 @@ module.exports = function(version, _options) { | |||
instruction = options.hooks.tokenizedInstruction(instruction); | |||
} | |||
|
|||
var waypoint = legIndex >= 0 && legIndex !== legCount - 1 ? this.ordinalize(language, legIndex + 1) : ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's the last of several waypoints, should we say "final destination"? The current code says only "destination".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but we currently do not have a translation for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This repository must have a source string before translators can provide translations in Transifex. Therefore, assuming that it’s a good idea to say “final destination”, this PR needs to add the “final destination” string to en.json. To avoid breaking the tests, I suppose we’d wait to make use of that string until enough translations are in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Therefore, assuming that it’s a good idea to say “final destination”, this PR needs to add the “final destination” string to en.json.
We used to have final destination
and it sounded grim. Would last destination
also work? Also we should make sure to not emit that if it's a one-leg route only.
index.js
Outdated
@@ -68,10 +68,11 @@ module.exports = function(version, _options) { | |||
|
|||
return config.join(''); | |||
}, | |||
compile: function(language, step) { | |||
compile: function(language, step, legIndex, legCount) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make this optional? For most cases (read: non-multi waypoint cases) we will not need these properties. I'd be good to put them into an options object.
compile: function(language, step, options) {
test/fixtures_test.js
Outdated
fs.writeFileSync( | ||
fileName, | ||
JSON.stringify({ | ||
step: step, | ||
instructions: instructionsForLanguages(step) | ||
instructions: instructionsForLanguages(step, legIndex, legCount), | ||
metadata: metadata |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we even need to add metadata if it's just an empty object most of the time?
"name": "Street Name" | ||
}, | ||
"instructions": { | ||
"de": "Sie haben Ihr erste Ziel erreicht, es befindet sich links von Ihnen", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need gendering of the adjective here 😢 Maybe we can get around this with some smart same-gender naming, I'll have a look ...
Now: Sie haben Ihr erste Ziel erreicht
.
Correct: Sie haben Ihr erstes Ziel erreicht
.
Haha, good point about “final destination”. 🙀 In an ideal world, we’d have a name for each waypoint that we’d say instead of “your destination”, but I suppose “your last destination” is passable. (The railfan in me would have it say “last scheduled station stop”. 😏) |
Readme and Changelog still need fixups. |
@freenerd will update the changelog when I update the package's version. |
index.js
Outdated
@@ -68,7 +68,7 @@ module.exports = function(version, _options) { | |||
|
|||
return config.join(''); | |||
}, | |||
compile: function(language, step) { | |||
compile: function(language, step, legOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we keep this with options
only? That would be consistent with the options
we already have for the module initialization.
"vi": "Đến nơi ", | ||
"zh-Hans": "您已经到达您的个目的地" | ||
}, | ||
"metadata": { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should become options
then as well
The iOS navigation SDK uses the Swift port of this library for logic such as what’s in this PR. Tracking a Swift port in Project-OSRM/osrm-text-instructions.swift#24. |
This adds instructions for arriving at waypoints and also fixes an issue with updating fixtures.
Necessary for mapbox/mapbox-navigation-ios#270
/cc @freenerd @patjouk @1ec5