Skip to content

Commit 2d0b769

Browse files
committed
Test phrases
1 parent 5511209 commit 2d0b769

File tree

19 files changed

+381
-33
lines changed

19 files changed

+381
-33
lines changed

index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,44 @@ module.exports = function(version, _options) {
194194

195195
return this.tokenize(instruction, replaceTokens, language);
196196
},
197+
compilePhrase: function(language, phrase, options) {
198+
if (!language) throw new Error('No language code provided');
199+
if (languages.supportedCodes.indexOf(language) === -1) throw new Error('language code ' + language + ' not loaded');
200+
if (!phrase) throw new Error('No phrase code provided');
201+
if (!options.steps || options.steps.length === 0) throw new Error('No steps provided');
202+
203+
var template = instructions[language][version].phrase[phrase];
204+
if (!template) throw new Error('Phrase "' + phrase + '" not found');
205+
206+
switch (phrase) {
207+
case 'two linked by distance':
208+
if (options.steps.length !== 2) throw new Error('Not enough or too many steps provided');
209+
if (!options.distance) throw new Error('No distance provided');
210+
211+
return this.tokenize(template, {
212+
'instruction_one': this.compile(language, options.steps[0], options),
213+
'instruction_two': this.compile(language, options.steps[1], options),
214+
distance: options.distance
215+
}, language);
216+
case 'two linked':
217+
if (options.steps.length !== 2) throw new Error('Not enough or too many steps provided');
218+
219+
return this.tokenize(template, {
220+
'instruction_one': this.compile(language, options.steps[0], options),
221+
'instruction_two': this.compile(language, options.steps[1], options)
222+
}, language);
223+
case 'one in distance':
224+
if (options.steps.length !== 1) throw new Error('Too many steps provided');
225+
if (!options.distance) throw new Error('No distance provided');
226+
227+
return this.tokenize(template, {
228+
'instruction_one': this.compile(language, options.steps[0], options),
229+
distance: options.distance
230+
}, language);
231+
default:
232+
throw new Error('Unrecognized phrase code ' + phrase);
233+
}
234+
},
197235
tokenize: function(instruction, tokens, language) {
198236
var output = Object.keys(tokens).reduce(function(memo, token) {
199237
return memo.replace('{' + token + '}', tokens[token]);

languages/translations/de.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Fähre nehmen Richtung {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Sie haben Ihr {nth} Ziel erreicht"

languages/translations/es.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Coge el ferry a {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Has llegado a tu {nth} destino"

languages/translations/fr.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Prendre le ferry en direction de {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Vous êtes arrivés à votre {nth} destination"

languages/translations/id.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Naik ferry menuju {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Anda telah tiba di tujuan ke-{nth}"

languages/translations/it.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Prendi il traghetto verso {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Sei arrivato alla tua {nth} destinazione"

languages/translations/nl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Neem het veer naar {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Je bent gearriveerd op de {nth} bestemming."

languages/translations/pl.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Weź prom w kierunku {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Dojechano do miejsca docelowego {nth}"

languages/translations/pt-BR.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Pegue a balsa sentido {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Você chegou ao seu {nth} destino"

languages/translations/ru.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Погрузитесь на паром в направлении {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Вы прибыли в {nth} пункт назначения"

languages/translations/sv.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Ta färjan mot {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Du är framme vid din {nth} destination"

languages/translations/uk.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Скористайтесь поромом у напрямку {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Ви прибули у ваш {nth} пункт призначення"

languages/translations/vi.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "Lên phà đi {destination}"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "Đến nơi {nth}"

languages/translations/zh-Hans.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"destination": "乘坐开往{destination}的轮渡"
5151
}
5252
},
53-
"phrase": {},
53+
"phrase": {
54+
"two linked by distance": "{instruction_one} then in {distance} {instruction_two}",
55+
"two linked": "{instruction_one} then {instruction_two}",
56+
"one in distance": "In {distance}, {instruction_one}"
57+
},
5458
"arrive": {
5559
"default": {
5660
"default": "您已经到达您的{nth}个目的地"
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"steps": [
3+
{
4+
"maneuver": {
5+
"type": "turn",
6+
"modifier": "left"
7+
},
8+
"mode": "driving",
9+
"name": "Way Name"
10+
}
11+
],
12+
"phrases": {
13+
"de": "In 0 units, Links abbiegen auf Way Name",
14+
"en": "In 0 units, Turn left onto Way Name",
15+
"es": "In 0 units, Gire a la izquierda en Way Name",
16+
"fr": "In 0 units, Tourner à gauche sur Way Name",
17+
"id": "In 0 units, Belok kiri ke Way Name",
18+
"it": "In 0 units, Svolta a sinistra in Way Name",
19+
"nl": "In 0 units, Ga linksaf naar Way Name",
20+
"pl": "In 0 units, Skręć w lewo na Way Name",
21+
"pt-BR": "In 0 units, Vire à esquerda em Way Name",
22+
"ru": "In 0 units, Поверните налево на Way Name",
23+
"sv": "In 0 units, Sväng vänster in på Way Name",
24+
"uk": "In 0 units, Поверніть ліворуч на Way Name",
25+
"vi": "In 0 units, Quẹo trái vào Way Name",
26+
"zh-Hans": "In 0 units, 左转,上Way Name"
27+
},
28+
"options": {
29+
"steps": [
30+
{
31+
"maneuver": {
32+
"type": "turn",
33+
"modifier": "left"
34+
},
35+
"mode": "driving",
36+
"name": "Way Name"
37+
}
38+
],
39+
"distance": "0 units"
40+
}
41+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
{
2+
"steps": [
3+
{
4+
"maneuver": {
5+
"type": "turn",
6+
"modifier": "left"
7+
},
8+
"mode": "driving",
9+
"name": "Way Name"
10+
},
11+
{
12+
"maneuver": {
13+
"type": "turn",
14+
"modifier": "left"
15+
},
16+
"name": "Way Name",
17+
"ref": "Ref1;Ref2"
18+
}
19+
],
20+
"phrases": {
21+
"de": "Links abbiegen auf Way Name then Links abbiegen auf Way Name (Ref1)",
22+
"en": "Turn left onto Way Name then Turn left onto Way Name (Ref1)",
23+
"es": "Gire a la izquierda en Way Name then Gire a la izquierda en Way Name (Ref1)",
24+
"fr": "Tourner à gauche sur Way Name then Tourner à gauche sur Way Name (Ref1)",
25+
"id": "Belok kiri ke Way Name then Belok kiri ke Way Name (Ref1)",
26+
"it": "Svolta a sinistra in Way Name then Svolta a sinistra in Way Name (Ref1)",
27+
"nl": "Ga linksaf naar Way Name then Ga linksaf naar Way Name (Ref1)",
28+
"pl": "Skręć w lewo na Way Name then Skręć w lewo na Way Name (Ref1)",
29+
"pt-BR": "Vire à esquerda em Way Name then Vire à esquerda em Way Name (Ref1)",
30+
"ru": "Поверните налево на Way Name then Поверните налево на Way Name (Ref1)",
31+
"sv": "Sväng vänster in på Way Name then Sväng vänster in på Way Name (Ref1)",
32+
"uk": "Поверніть ліворуч на Way Name then Поверніть ліворуч на Way Name (Ref1)",
33+
"vi": "Quẹo trái vào Way Name then Quẹo trái vào Way Name (Ref1)",
34+
"zh-Hans": "左转,上Way Name then 左转,上Way Name (Ref1)"
35+
},
36+
"options": {
37+
"steps": [
38+
{
39+
"maneuver": {
40+
"type": "turn",
41+
"modifier": "left"
42+
},
43+
"mode": "driving",
44+
"name": "Way Name"
45+
},
46+
{
47+
"maneuver": {
48+
"type": "turn",
49+
"modifier": "left"
50+
},
51+
"name": "Way Name",
52+
"ref": "Ref1;Ref2"
53+
}
54+
]
55+
}
56+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"steps": [
3+
{
4+
"maneuver": {
5+
"type": "turn",
6+
"modifier": "left"
7+
},
8+
"mode": "driving",
9+
"name": "Way Name"
10+
},
11+
{
12+
"maneuver": {
13+
"type": "turn",
14+
"modifier": "left"
15+
},
16+
"name": "Way Name",
17+
"ref": "Ref1;Ref2"
18+
}
19+
],
20+
"phrases": {
21+
"de": "Links abbiegen auf Way Name then in 0 units Links abbiegen auf Way Name (Ref1)",
22+
"en": "Turn left onto Way Name then in 0 units Turn left onto Way Name (Ref1)",
23+
"es": "Gire a la izquierda en Way Name then in 0 units Gire a la izquierda en Way Name (Ref1)",
24+
"fr": "Tourner à gauche sur Way Name then in 0 units Tourner à gauche sur Way Name (Ref1)",
25+
"id": "Belok kiri ke Way Name then in 0 units Belok kiri ke Way Name (Ref1)",
26+
"it": "Svolta a sinistra in Way Name then in 0 units Svolta a sinistra in Way Name (Ref1)",
27+
"nl": "Ga linksaf naar Way Name then in 0 units Ga linksaf naar Way Name (Ref1)",
28+
"pl": "Skręć w lewo na Way Name then in 0 units Skręć w lewo na Way Name (Ref1)",
29+
"pt-BR": "Vire à esquerda em Way Name then in 0 units Vire à esquerda em Way Name (Ref1)",
30+
"ru": "Поверните налево на Way Name then in 0 units Поверните налево на Way Name (Ref1)",
31+
"sv": "Sväng vänster in på Way Name then in 0 units Sväng vänster in på Way Name (Ref1)",
32+
"uk": "Поверніть ліворуч на Way Name then in 0 units Поверніть ліворуч на Way Name (Ref1)",
33+
"vi": "Quẹo trái vào Way Name then in 0 units Quẹo trái vào Way Name (Ref1)",
34+
"zh-Hans": "左转,上Way Name then in 0 units 左转,上Way Name (Ref1)"
35+
},
36+
"options": {
37+
"steps": [
38+
{
39+
"maneuver": {
40+
"type": "turn",
41+
"modifier": "left"
42+
},
43+
"mode": "driving",
44+
"name": "Way Name"
45+
},
46+
{
47+
"maneuver": {
48+
"type": "turn",
49+
"modifier": "left"
50+
},
51+
"name": "Way Name",
52+
"ref": "Ref1;Ref2"
53+
}
54+
],
55+
"distance": "0 units"
56+
}
57+
}

0 commit comments

Comments
 (0)