Skip to content

Commit 59d96ce

Browse files
authored
Rewrite documentation (#227)
* Rewrote documentation Added a guide to contributing to this project, as well as documentation on the abbreviation file format. Moved the grammar file documentation to the grammar folder. Rewrote large sections of the readme, relegating some content to other Markdown documents, and renamed the file for consistency. * Fixed code blocks in grammar documentation The code blocks were causing colored diffs on GitHub to go haywire. * Simplified language Also added next steps after submitting a localization. * Added examples to abbreviation documentation * Fixed link
1 parent 207f544 commit 59d96ce

File tree

5 files changed

+229
-147
lines changed

5 files changed

+229
-147
lines changed

CONTRIBUTING.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Contributing to OSRM Text Instructions
2+
3+
## Reporting an issue
4+
5+
Bug reports and feature requests are more than welcome, but please consider the following tips so we can respond to your feedback more effectively.
6+
7+
Before reporting a bug here, please determine whether the problem is due to OSRM Text Instructions itself or if the problem is in a related product:
8+
9+
* Are you currently running the [Mapbox Navigation SDK](https://www.mapbox.com/navigation-sdk/) inside an application?
10+
* Tap the feedback button to send feedback directly to Mapbox.
11+
* Does the issue occur only on the [OSRM demo server](http://map.project-osrm.org/)?
12+
* Report the issue in the [osrm-frontend](https://github.com/Project-OSRM/osrm-frontend/) repository’s issue tracker.
13+
* Does the issue occur only in the [Mapbox Directions API](https://www.mapbox.com/api-documentation/#directions)?
14+
* Report the issue in the [Mapbox Feedback](https://www.mapbox.com/feedback/) tool.
15+
* Does the issue occur only when getting directions on the [OpenStreetMap](https://www.openstreetmap.org/) homepage?
16+
* Report the issue in the [openstreetmap-website](https://github.com/openstreetmap/openstreetmap-website/) repository’s issue tracker.
17+
18+
When reporting a bug in the navigation SDK itself, please provide:
19+
20+
* The OSRM Text Instructions version number
21+
* The language being used, if the issue is specific to a language
22+
* A demonstration of the problem, either a link to a route on the [OSRM demo server](http://map.project-osrm.org/) or sample code
23+
24+
## Opening a pull request
25+
26+
Pull requests are appreciated. If your PR includes any changes that would impact developers or end users, please mention those changes in the “master” section of [CHANGELOG.md](CHANGELOG.md), noting the PR number. Examples of noteworthy changes include new features, fixes for user-visible bugs, and renamed or deleted public symbols.
27+
28+
## Adding a new feature
29+
30+
The development language of this project is English (`en`). To ensure that a new feature is functional regardless of the language in use, you also need to add any strings that the feature uses to all the localizations, not just English:
31+
32+
* If the new string is similar to an existing string, duplicate the existing string in the same localization to fill in the missing string.
33+
* If no existing string is similar, copy the English string to fill in the missing string.
34+
35+
This way, the instruction is more likely to make sense to the user even if it’s imperfect. Once the feature is merged, we rely on translators to [update their localizations](#adding-or-updating-a-localization) with better translations.
36+
37+
This library relies on automatically generated test fixtures to show the effect your changes have on this library’s output in each language:
38+
39+
* To update the instructions in the fixture files, run `UPDATE=1 npm test`.
40+
* To create new fixtures, add them to test/fixtures_test.js, then run `UPDATE=1 npm test`.
41+
* Integration tests based on these fixtures help to prevent unexpected regressions. Run the integration tests using `npm install && npm test`.
42+
43+
## Adding or updating a localization
44+
45+
We welcome your help in making OSRM Text Instructions available in the languages that you and your users speak. Localizations are maintained [at Transifex](https://www.transifex.com/project-osrm/osrm-text-instructions/), then committed to the [languages/](https://github.com/Project-OSRM/osrm-text-instructions/tree/master/languages/) folder of this repository when ready. If your language already has a translation, feel free to complete or proofread it. Otherwise, please [request your language](https://www.transifex.com/project-osrm/osrm-text-instructions/) so you can start translating. Transifex has a Web interface, so you don’t need specialized software to get started.
46+
47+
Once you’ve finished translating OSRM Text Instructions into a new language in Transifex, open an issue in this repository asking to pull in your localization. Or do it yourself and open a pull request with the results:
48+
49+
1. _(First time only.)_ Create a plain text file named transifex.auth, and it put in the root folder of this repository. (This file is ignored by Git, so you don’t need to worry about accidentally committing it.) Fill in your [Transifex credentials](https://docs.transifex.com/api/introduction#authentication):
50+
```json
51+
{
52+
"user": "username",
53+
"pass": "password"
54+
}
55+
```
56+
1. _(First time only.)_ Create an empty translation file by running `echo "{}" > languages/translations/xyz.json`, where _xyz_ is a language code, such as `en`, `fil`, `pt-BR`, or `zh-Hant`.
57+
1. _(First time only.)_ In languages.js, require the new file and add an entry for _xyz_ to the `instructions` variable.
58+
1. Pull the translations from Transifex by running `npm run transifex`.
59+
1. _(Optional.)_ If your language has special casing rules or you need to systematically change what’s imported from Transifex, add an override file to languages/overrides/_xyz_.json.
60+
1. _(Optional.)_ [Add an abbreviation file](languages/abbreviations/README.md) to languages/abbreviations/_xyz_.json that determines how words in road names and place names can be abbreviated when instructions are displayed visually.
61+
1. _(Optional.)_ [Add a grammar file](languages/grammar/README.md) to languages/grammar/_xyz_.json that specifies the declension rules to apply to road and place names in a sentence.
62+
1. Generate test fixtures for the language by running `UPDATE=1 npm test`. Run `git diff` to inspect the changes; make sure your translations make sense in the context of a complete sentence. Once you’re satisfied with the results, commit and push your changes.
63+
64+
After we merge the PR containing your localization updates and release a new version of OSRM Text Instructions, the [Mapbox Directions API](https://www.mapbox.com/api-documentation/#directions) will begin to accept the new language in the `language` query parameter. If you also want the OSRM demo server to display instructions in the new language, add the language to [osrm-frontend](https://github.com/Project-OSRM/osrm-frontend/).
65+
66+
### Related projects
67+
68+
Please consider also translating the following related projects, which work together with OSRM Text Instructions to give the user a complete turn-by-turn navigation experience:
69+
70+
* [Mapbox Navigation SDK for Android](https://www.transifex.com/mapbox/mapbox-navigation-sdk-for-android/), which adds turn-by-turn navigation functionality to an Android application, including voice instructions powered by this library ([instructions](https://github.com/mapbox/mapbox-navigation-android/#translations))
71+
* [Mapbox Navigation SDK for iOS](https://www.transifex.com/mapbox/mapbox-navigation-ios/), the corresponding library for iOS applications ([instructions](https://github.com/mapbox/mapbox-navigation-ios/blob/master/CONTRIBUTING.md#adding-or-updating-a-localization))
72+
* This SDK automatically requests [voice instructions in the system language](https://github.com/mapbox/mapbox-navigation-ios/blob/master/docs/guides/Localization%20and%20Internationalization.md#spoken-instructions) if the SDK is also available in that language.
73+
* [Mapbox Maps SDK](https://www.transifex.com/mapbox/mapbox-gl-native/), which is responsible for the map view and minor UI elements such as the compass ([instructions](https://github.com/mapbox/mapbox-gl-native/blob/master/platform/ios/DEVELOPING.md#adding-a-localization))
74+
75+
## Releasing a new version
76+
77+
1. In CHANGELOG.md, replace the “master” heading with the new version number.
78+
1. Bump the `version` in package.json.
79+
1. Run `git commit -a | "vx.y.z"`, including a list of changes from the changelog in the commit message.
80+
1. Run `git tag vx.y.z -a`, including the same list in the tag message.
81+
1. Run `git push && git push --tags` to push the changes to the repository.
82+
1. Open a pull request, get a review, and merge to master. (master is a protected branch.)
83+
1. Run `npm publish` to publish the package to the general public.

README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
[<img src="https://travis-ci.org/Project-OSRM/osrm-text-instructions.svg?branch=master" align="right" alt="Build status">](https://travis-ci.org/Project-OSRM/osrm-text-instructions)
2+
3+
# OSRM Text Instructions
4+
5+
OSRM Text Instructions is a Node.js library that transforms route data generated by [OSRM](http://www.project-osrm.org/) into localized turn instructions to be displayed visually or read aloud by a text-to-speech engine. OSRM Text Instructions is the basis of guidance instructions in [osrm-frontend](https://github.com/Project-OSRM/osrm-frontend/), the [Mapbox Directions API](https://www.mapbox.com/api-documentation/#directions), and the [Mapbox Navigation SDK](https://www.mapbox.com/navigation-sdk/).
6+
7+
* **Global**: Text instructions are available in over a dozen languages via [Transifex](https://www.transifex.com/project-osrm/osrm-text-instructions/). [Abbreviations](languages/abbreviations/README.md) and [advanced grammatical transformations](languages/grammar/README.md) are available in some languages.
8+
* **Customizable**: Flexible options allow you to format and tweak the results to your liking.
9+
* **Cross-platform**: A data-driven approach facilitates implementations in other programming languages. OSRM Text Instructions is also available [in Swift and Objective-C](https://github.com/Project-OSRM/osrm-text-instructions.swift/) (for iOS, macOS, tvOS, and watchOS) and [in Java](https://github.com/Project-OSRM/osrm-text-instructions.java/) (for Android and Java SE).
10+
* **Well-tested**: A data-driven test suite ensures compatibility across languages and platforms.
11+
12+
## Usage
13+
14+
[![NPM](https://nodei.co/npm/osrm-text-instructions.png)](https://npmjs.org/package/osrm-text-instructions/)
15+
16+
```js
17+
var version = 'v5';
18+
var osrmTextInstructions = require('osrm-text-instructions')(version);
19+
20+
// If you’re unsure if the user’s locale is supported, use `getBestMatchingLanguage` method to find an appropriate language.
21+
var language = osrmTextInstructions.getBestMatchingLanguage('en-US');
22+
23+
response.legs.forEach(function(leg) {
24+
leg.steps.forEach(function(step) {
25+
instruction = osrmTextInstructions.compile(language, step, options)
26+
});
27+
});
28+
```
29+
30+
#### Parameters `require('osrm-text-instructions')(version)`
31+
32+
parameter | required? | values | description
33+
---|----|----|---
34+
`version` | required | `v5` | Major OSRM version
35+
36+
#### Parameters `compile(language, step, options)`
37+
38+
parameter | required? | values | description
39+
---|----|----|---
40+
`language` | required | `en` `de` `zh-Hans` `fr` `nl` `ru` [and more](https://github.com/Project-OSRM/osrm-text-instructions/tree/master/languages/translations/) | Compiling instructions for the selected language code.
41+
`step` | required | [OSRM route step object](https://github.com/Project-OSRM/osrm-backend/blob/master/docs/http.md#routestep-object) | The RouteStep as it comes out of OSRM
42+
`options` | optional | Object | See [below](#options)
43+
44+
##### Options
45+
46+
key | type | description
47+
----|----|----
48+
`legCount` | integer | Number of legs in the route
49+
`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
50+
`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
51+
52+
`formatToken` takes two parameters:
53+
54+
* `token`: A string that indicates the kind of token, such as `way_name` or `direction`
55+
* `value`: A grammatical string for this token, capitalized if the token appears at the beginning of the instruction
56+
57+
and returns a string.
58+
59+
## Architecture
60+
61+
* index.js contains the main transformation logic in JavaScript.
62+
* languages/ contains the localization files, including raw format strings, abbreviation files, and grammar rules.
63+
* languages.js loads the localizations and contains some localization-related helper functions.
64+
* test/ contains data-driven integration tests and test fixtures for all supported languages.
65+
66+
## Contributing
67+
68+
We welcome feedback, code contributions, and translations! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
69+
70+
[![Transifex](https://www.transifex.com/projects/p/osrm-text-instructions/resource/enjson/chart/image_png)](https://www.transifex.com/project-osrm/osrm-text-instructions/)

Readme.md

Lines changed: 0 additions & 121 deletions
This file was deleted.

0 commit comments

Comments
 (0)