You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Grammar.md
+17-4Lines changed: 17 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,7 @@ The quite universal and simplier solution is the changing street names with the
15
15
The required grammatical case should be specified right in instruction's substitution variables:
16
16
17
17
-`{way_name}` and `{rotary_name}` variables in translated instructions should be appended with required grammar case name after colon: `{way_name:accusative}` for example
18
-
-[languages/grammar](languages/grammar/) folder should contain language-specific JSON file with regular expressions for specified grammar case:
18
+
-[languages/grammar](languages/grammar/) folder should contain language-specific JSON file with regular expressions for specified grammatical case:
19
19
```json
20
20
{
21
21
"v5": {
@@ -28,9 +28,21 @@ The required grammatical case should be specified right in instruction's substit
28
28
- Instruction text formatter ([index.js](index.js) in this module) should:
29
29
- check `{way_name}` and `{rotary_name}` variables for optional grammar case after colon: `{way_name:accusative}`
30
30
- find appropriate regular expressions block for target language and specified grammar case
31
-
- call standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) for each expression in block passing result from previous call to the next; the first call should enclose original street name with whitespaces to make parsing words in names a bit simplier.
31
+
- call standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace) for each expression in block passing result from previous call to the next; the first call should enclose original street name with whitespaces to make parsing several words inside name a bit simplier.
32
32
- Strings replacement with regular expression is available in almost all other programming language and so this should not be the problem for other code used OSRM Text Instructions' data only.
33
-
- If there is no regular expression matched source name (that's for names from foreign country for example), original name is returned without changes. This is also expected behavior of standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace). And the same behavior is expected in case of missing grammar JSON file or grammar case inside it.
33
+
- Grammar JSON could have [regular expression flags in JS notation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp):
34
+
```json
35
+
{
36
+
"meta": {
37
+
"regExpFlags": "ig"
38
+
},
39
+
```
40
+
- Please note, not all JS regular expression flags could be supported in other languages.
41
+
For example, [OSRM Text Instructions for Swift](https://github.com/Project-OSRM/osrm-text-instructions.swift/) don't support "non-global match" and so always supposes `g` flag turned on.
42
+
So if some regular expressions suppose stopping after their match, please include `^` and/or `$` into patterns for exact matching or return "finished" string in replace expression without enclosing whitespaces.
43
+
- If there is no regular expression matched source name (that's for names from foreign country for example), original name is returned without changes.
44
+
This is also expected behavior of standard [string replace with regular expression](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace).
45
+
And the same behavior is expected in case of missing grammar JSON file or grammar case inside it.
34
46
35
47
### Example
36
48
@@ -50,4 +62,5 @@ Russian _"Большая Монетная улица"_ street from St Petersburg
50
62
51
63
- Russian regular expressions are based on [Garmin Russian TTS voices update](https://github.com/yuryleb/garmin-russian-tts-voices) project; see [file with regular expressions to apply to source text before pronouncing by TTS](https://github.com/yuryleb/garmin-russian-tts-voices/blob/master/src/Pycckuu__Milena%202.10/RULESET.TXT).
52
64
- There is another grammar-supporting module - [jquery.i18n](https://github.com/wikimedia/jquery.i18n) - but unfortunately it has very poor implementation in part of grammatical case applying and is supposed to work with single words only.
53
-
- Actually it would be great to get street names also in target language not from default OSM `name` only - there are several multi-lingual countries supporting several `name:<lang>` names for streets. But this the subject to address to [OSRM engine](https://github.com/Project-OSRM/osrm-backend) first.
65
+
- Actually it would be great to get street names also in target language not from default OSM `name` only - there are several multi-lingual countries supporting several `name:<lang>` names for streets.
66
+
But this the subject to address to [OSRM engine](https://github.com/Project-OSRM/osrm-backend).
0 commit comments