Skip to content
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

Arrival instruction includes an optional named waypoint #235

Merged
merged 11 commits into from
Apr 11, 2018
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ parameter | required? | values | description
key | type | description
----|----|----
`legCount` | integer | Number of legs in the route
`legIndex` | integer | Zero-based index of the leg containing the step; together with `legIndex`, this option determines whether an arrival instruction indicates which waypoint the user has arrived at
`legIndex` | integer | Zero-based index of the leg containing the step; together with `legCount`, this option determines which waypoint the user has arrived at
`formatToken` | function | Function that formats the given token value after grammaticalization and capitalization but before the value is inserted into the instruction string; useful for wrapping tokens in markup
`waypointName` | string | Optional custom name for the leg's destination, replaces `"your {nth} destination"`

`formatToken` takes two parameters:

Expand Down
24 changes: 21 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,25 @@ module.exports = function(version) {

return wayName;
},
compile: function(language, step, options) {

/**
* Formulate a localized text instruction from a step.
*
* @param {string} language Language code.
* @param {object} step Step including maneuver property.
* @param {object} opts Additional options.
* @param {string} opts.legIndex Index of leg in the route.
* @param {string} opts.legCount Total number of legs in the route.
* @param {array} opts.classes List of road classes.
* @param {string} opts.waypointName Name of waypoint for arrival instruction.
*
* @return {string} Localized text instruction.
*/
compile: function(language, step, opts) {
if (!language) throw new Error('No language code provided');
if (languages.supportedCodes.indexOf(language) === -1) throw new Error('language code ' + language + ' not loaded');
if (!step.maneuver) throw new Error('No step maneuver provided');
var options = opts || {};

var type = step.maneuver.type;
var modifier = step.maneuver.modifier;
Expand Down Expand Up @@ -185,6 +200,8 @@ module.exports = function(version) {
instruction = instructionObject.exit;
} else if (wayName && instructionObject.name) {
instruction = instructionObject.name;
} else if (options.waypointName && instructionObject.named) {
instruction = instructionObject.named;
} else {
instruction = instructionObject.default;
}
Expand All @@ -199,7 +216,7 @@ module.exports = function(version) {
firstDestination = destinationRef || destination || '';
}

var nthWaypoint = options && options.legIndex >= 0 && options.legIndex !== options.legCount - 1 ? this.ordinalize(language, options.legIndex + 1) : '';
var nthWaypoint = options.legIndex >= 0 && options.legIndex !== options.legCount - 1 ? this.ordinalize(language, options.legIndex + 1) : '';

// Replace tokens
// NOOP if they don't exist
Expand All @@ -212,7 +229,8 @@ module.exports = function(version) {
'lane_instruction': laneInstruction,
'modifier': instructions[language][version].constants.modifier[modifier],
'direction': this.directionFromDegree(language, step.maneuver.bearing_after),
'nth': nthWaypoint
'nth': nthWaypoint,
'waypoint_name': options.waypointName
};

return this.tokenize(language, instruction, replaceTokens, options);
Expand Down
6 changes: 4 additions & 2 deletions languages/overrides/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ function optionize(phrase) {
var re = new RegExp(pattern[0], 'gi');
result = result.replace(re, pattern[1]);
});

return result;
};
}

function iterate(values) {
Object.keys(values).forEach(function (key) {
Expand All @@ -27,10 +28,11 @@ function iterate(values) {
iterate(value);
}
});
};
}

module.exports = function(content) {
// Iterate all content string values recursively
iterate(content.v5);

return content;
};
24 changes: 16 additions & 8 deletions languages/translations/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,57 @@
"default": "Du er ankommet til din {nth} destination",
"upcoming": "Du vil ankomme til din {nth} destination",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}"
},
"left": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til venstre",
"upcoming": "Du vil ankomme til din {nth} destination på venstre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til venstre"
},
"right": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til højre",
"upcoming": "Du vil ankomme til din {nth} destination på højre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til højre"
},
"sharp left": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til venstre",
"upcoming": "Du vil ankomme til din {nth} destination på venstre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til venstre"
},
"sharp right": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til højre",
"upcoming": "Du vil ankomme til din {nth} destination på højre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til højre"
},
"slight right": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til højre",
"upcoming": "Du vil ankomme til din {nth} destination på højre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til højre"
},
"slight left": {
"default": "Du er ankommet til din {nth} destination, som befinder sig til venstre",
"upcoming": "Du vil ankomme til din {nth} destination på venstre hånd",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, som befinder sig til venstre"
},
"straight": {
"default": "Du er ankommet til din {nth} destination, der befinder sig lige frem",
"upcoming": "Du vil ankomme til din {nth} destination foran dig",
"short": "Du er ankommet",
"short-upcoming": "Du vil ankomme"
"short-upcoming": "Du vil ankomme",
"named": "Du er ankommet til {waypoint_name}, der befinder sig lige frem"
}
},
"continue": {
Expand Down
24 changes: 16 additions & 8 deletions languages/translations/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,57 @@
"default": "Sie haben Ihr {nth} Ziel erreicht",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}"
},
"left": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich links"
},
"right": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich rechts"
},
"sharp left": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich links"
},
"sharp right": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich rechts"
},
"slight right": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich rechts",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich rechts"
},
"slight left": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich links",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich links"
},
"straight": {
"default": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich geradeaus",
"upcoming": "Sie haben Ihr {nth} Ziel erreicht, es befindet sich geradeaus",
"short": "Sie haben Ihr {nth} Ziel erreicht",
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht"
"short-upcoming": "Sie haben Ihr {nth} Ziel erreicht",
"named": "Sie haben Ihr {waypoint_name}, es befindet sich geradeaus"
}
},
"continue": {
Expand Down
24 changes: 16 additions & 8 deletions languages/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,57 @@
"default": "You have arrived at your {nth} destination",
"upcoming": "You will arrive at your {nth} destination",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}"
},
"left": {
"default": "You have arrived at your {nth} destination, on the left",
"upcoming": "You will arrive at your {nth} destination, on the left",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the left"
},
"right": {
"default": "You have arrived at your {nth} destination, on the right",
"upcoming": "You will arrive at your {nth} destination, on the right",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the right"
},
"sharp left": {
"default": "You have arrived at your {nth} destination, on the left",
"upcoming": "You will arrive at your {nth} destination, on the left",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the left"
},
"sharp right": {
"default": "You have arrived at your {nth} destination, on the right",
"upcoming": "You will arrive at your {nth} destination, on the right",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the right"
},
"slight right": {
"default": "You have arrived at your {nth} destination, on the right",
"upcoming": "You will arrive at your {nth} destination, on the right",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the right"
},
"slight left": {
"default": "You have arrived at your {nth} destination, on the left",
"upcoming": "You will arrive at your {nth} destination, on the left",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, on the left"
},
"straight": {
"default": "You have arrived at your {nth} destination, straight ahead",
"upcoming": "You will arrive at your {nth} destination, straight ahead",
"short": "You have arrived",
"short-upcoming": "You will arrive"
"short-upcoming": "You will arrive",
"named": "You have arrived at {waypoint_name}, straight ahead"
}
},
"continue": {
Expand Down
24 changes: 16 additions & 8 deletions languages/translations/eo.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,49 +62,57 @@
"default": "Vi atingis vian {nth} celon",
"upcoming": "Vi atingos vian {nth} celon",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name}"
},
"left": {
"default": "Vi atingis vian {nth} celon ĉe maldekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe maldekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe maldekstre"
},
"right": {
"default": "Vi atingis vian {nth} celon ĉe dekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe dekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe dekstre"
},
"sharp left": {
"default": "Vi atingis vian {nth} celon ĉe maldekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe maldekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe maldekstre"
},
"sharp right": {
"default": "Vi atingis vian {nth} celon ĉe dekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe dekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe dekstre"
},
"slight right": {
"default": "Vi atingis vian {nth} celon ĉe dekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe dekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe dekstre"
},
"slight left": {
"default": "Vi atingis vian {nth} celon ĉe maldekstre",
"upcoming": "Vi atingos vian {nth} celon ĉe maldekstre",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name} ĉe maldekstre"
},
"straight": {
"default": "Vi atingis vian {nth} celon",
"upcoming": "Vi atingos vian {nth} celon rekte",
"short": "Vi atingis",
"short-upcoming": "Vi atingos"
"short-upcoming": "Vi atingos",
"named": "Vi atingis {waypoint_name}"
}
},
"continue": {
Expand Down
Loading