Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

osrm-text-instructions

Package Overview
Dependencies
Maintainers
10
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

osrm-text-instructions

OSRM Text Instructions

  • 0.11.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16K
decreased by-0.96%
Maintainers
10
Weekly downloads
 
Created
Source

OSRM Text Instructions

Build Status


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.

NPM

Design goals

  • Cross platform Use a data-driven approach that makes implementations in other programming environments easy to write
  • Test suite Have a data-driven test suite with fixtures which can be used cross-platform
  • Translation Allow for translations via Transifex
  • Customization Users should be able to easily fork or monkey-patch the results to adjust to their own liking

JavaScript Usage

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)
  });
});
Parameters require('osrm-text-instructions')(version)
parameterrequired?valuesdescription
versionrequiredv5Major OSRM version
Parameters compile(language, step, options)
parameterrequired?valuesdescription
languagerequireden de zh-Hans fr nl ru and moreCompiling instructions for the selected language code.
steprequiredOSRM route step objectThe RouteStep as it comes out of OSRM
optionsoptionalObjectSee below
Options
keytypedescription
legCountintegerNumber of legs in the route
legIndexintegerZero-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
formatTokenfunctionFunction 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 instruction

and returns a string.

Development

Architecture
  • index.js holds the main transformation logic in javascript
  • instructions/ holds the translateable strings
Tests

Tests are data-driven integration tests for the english language.

To run them yourself for the JavaScript implementation:

npm install
npm test
Generate Fixtures

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.

Translations

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:

  • Go to Transifex and create the new translation there
  • When the translation on Transifex is ready, pull in the translation file:
    • Create an empty translation file echo "{}" > languages/translations/{language_code}.json
    • Add the new translation file and language code to ./languages.js
    • If needed: make overrides in languages/overrides/{language_code}.json
    • npm run transifex
  • Generate fixture strings for the tests via UPDATE=1 npm test (see changes in git diff)
  • Make a PR
Release
  • git checkout master
  • Update CHANGELOG.md
  • Bump version in package.json
  • git commit -a | "vx.y.z" with Changelog list in commit message
  • git tag vx.y.z -a with Changelog list in tag message
  • git push origin master; git push origin --tags
  • npm publish

FAQs

Package last updated on 03 Jan 2018

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc