
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
osrm-text-instructions
Advanced tools
OSRM Text Instructions transforms OSRM route responses into localized text instructions. This repository contains the canonical implementation of this library written in JavaScript. OSRM Text Instructions is also available in Swift and Objective-C (for iOS, macOS, tvOS, and watchOS) and in Java (for Android and Java SE).
OSRM Text Instructions has been translated into several languages. Please help us add support for the languages you speak using Transifex.
OSRM Text Instructions could support grammatical cases for street names for some languages.
Grammatical cases and other translated strings customization after Transifex is handled by override scripts.
var version = 'v5';
var osrmTextInstructions = require('osrm-text-instructions')(version);
// If you’re unsure if the user’s locale is supported, use `getBestMatchingLanguage` method to find an appropriate language.
var language = osrmTextInstructions.getBestMatchingLanguage('en-US');
response.legs.forEach(function(leg) {
leg.steps.forEach(function(step) {
instruction = osrmTextInstructions.compile(language, step, options)
});
});
require('osrm-text-instructions')(version)
parameter | required? | values | description |
---|---|---|---|
version | required | v5 | Major OSRM version |
compile(language, step, options)
parameter | required? | values | description |
---|---|---|---|
language | required | en de zh-Hans fr nl ru and more | Compiling instructions for the selected language code. |
step | required | OSRM route step object | The RouteStep as it comes out of OSRM |
options | optional | Object | See below |
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 |
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 |
formatToken
takes two parameters:
token
: A string that indicates the kind of token, such as way_name
or direction
value
: A grammatical string for this token, capitalized if the token appears at the beginning of the instructionand returns a string.
index.js
holds the main transformation logic in javascriptinstructions/
holds the translateable stringsTests are data-driven integration tests for the english language.
To run them yourself for the JavaScript implementation:
npm install
npm test
Fixtures are programatically created and updated via test/fixtures_test
. To update the instructions in the fixture files, run UPDATE=1 npm test
. To create new fixtures, add them to test/fixtures_test
, then run UPDATE=1 npm test
.
The main language of this project is English en
. We support other languages via translations, as seen in languages/translations
.
When adding a new instruction option, you should first provide the english use case. You should then add this use case to all other translations, opting for the closest value currently present in the target langague first and then defaulting to english if nothing acceptable is present. This way there is a better chance the instruction will make sense to the user even if its not perfect. In time translators will see this and improve it.
You can help translating on the web via Transifex
To add an own translations:
echo "{}" > languages/translations/{language_code}.json
./languages.js
languages/overrides/{language_code}.json
npm run transifex
UPDATE=1 npm test
(see changes in git diff
)git checkout master
git commit -a | "vx.y.z"
with Changelog list in commit messagegit tag vx.y.z -a
with Changelog list in tag messagegit push origin master; git push origin --tags
npm publish
0.10.7 2017-12-05
formatToken
from being called on refs or names when the way has only a ref or a name. #193FAQs
OSRM Text Instructions
We found that osrm-text-instructions demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.