Constructor
new NavigationTranslator()
- Since:
- 1.9.3 instantiated by visioweb.Mapviewer
- See:
Examples
mapviewer.setupNavigationTranslator(vgPlaces);
var languageString = 'en'; // 'fr'
mapviewer.navigationTranslator.translateInstructions(routeResultData.navigation, languageString);
// vgPlaces must have the form
{
placeID001: {
name: 'shop #001',
description: 'the first shop'
},
placeID002: {
name: 'shop #002',
description: 'the second shop'
},
...
}
// translation must have the form
// Note _before_instruction keyword or _before_instruction_and_floor_change in order to put some words before.
// Can be useful for some languages in Asia
function setupSpanish() {
var esTranslation =
{
maneuvers: {
unknown: '<desconocido>', // eVgManeuverTypeUnknown
goStraight: ' ir directamente',
turnGentleRight: ' gira ligeramente a la derecha',
turnGentleLeft: ' gira ligeramente a la izquierda',
turnRight: ' gira a la derecha',
turnLeft: ' gira a la izquierda',
turnSharpRight: ' gire bruscamente a la derecha',
turnSharpLeft: ' gire bruscamente a la izquierda',
UTurnRight: ' hacer un giro en U a la derecha',
UTurnLeft: ' hacer un giro en U a la izquierda',
start: ' salida',
end: ' llegada',
goUp: ' sube las escaleras %L',
goDown: ' bajar la escalera %L',
changeModality: ' cambiar de medio de transporte: %M',
changeLayer: ' cambiar de edificio',
waypoint: 'deténgase' // in 1.7.17 it said also 'l'escale #'
},
nextManeuvers: {
unknown: '<desconocido>', // eVgManeuverTypeUnknown
goStraight: ' siga derecho',
turnGentleRight: ' gira ligeramente a la derecha',
turnGentleLeft: ' gira ligeramente a la izquierda',
turnRight: ' gira a la derecha',
turnLeft: ' gira a la izquierda',
turnSharpRight: ' gire bruscamente a la derecha',
turnSharpLeft: ' gire bruscamente a la izquierda',
UTurnRight: ' hacer un giro en U a la derecha',
UTurnLeft: ' hacer un giro en U a la izquierda',
start: ' salida',
end: ' habrás llegado',
goUp: ' sube',
goDown: ' bajar',
changeModality: ' cambiar de medio de transporte: %M',
changeLayer: ' cambiar de edificio',
waypoint: 'deténgase' // eVgManeuverTypeWaypoint
},
keywords: {
for: '',
for_before_instruction: ' durante ',
then: ' y ',
and: ' y ',
near: '',
near_before_instruction: '',
near_before_instruction_and_floor_change: ' cerca de %P ',
using: '',
using_before_instruction: ' tomando ',
stairway: '',
stairway_before_instruction: 'las escaleras',
escalator: '',
escalator_before_instruction: 'la escalera mecánica',
lift: '',
lift_before_instruction: 'el ascensor'
},
durations: {
seconds: '',
seconds_before_instruction: 'algunos segundos',
oneMinute: '',
oneMinute_before_instruction: 'alrededor de un minuto',
customRangeTimeArray_before_instruction: [{rangeMin:0,rangeMax:1,minute:'minute'}],
customRangeTimeArray: [{rangeMin:0.0,rangeMax:1.0,time:'%d seconds'}, {rangeMin:1.0,rangeMax:5.0,time:'%d minuty'}],
minutes: '',
minutes_before_instruction: 'alrededor %d minutas'
}
};
essential.navigation.translator.addOrUpdateLanguage('es', JSON.stringify(esTranslation));
essential.navigation.setLanguageCode({languageCode:'es'});
}
Methods summary
Name | Description |
---|---|
addOrUpdateLanguage | adds a new language to the translator or updates an existing one |
getLanguage | returns a JSON string with the targeted localization. can be used as a template for adding a new language using getLanguage('default') |
getLanguageCodes | returns an array of supported language codes |
setFloors | set floor names |
translateInstructions | translates all the instructions in pNavigation.instructions, augmenting each instruction with .brief, .detailed, .duration, .durationInSeconds |
updateDurationForLanguage | updates the localized string for a given duration in a given language |
updateKeywordForLanguage | updates the localized string for a given keyword in a given language |
updateManeuverForLanguage | updates the localized string for a given maneuver in a given language |
updateNextManeuverForLanguage | updates the localized string for a given next maneuver (maneuver following another) in a given language |
Methods detail
addOrUpdateLanguage(pLanguageCode, pJSONString) → {boolean}
adds a new language to the translator or updates an existing one
Parameters:
Name | Type | Description |
---|---|---|
pLanguageCode |
string | short string describing how you will refer to it later. Default language codes are 'en' and 'fr'. |
pJSONString |
string | JSON string (see example below). |
Returns:
- Type
- boolean
Example
{
maneuvers: {...}, // map of strings providing the localization for all maneuvers
nextManeuvers: {...}, // map of strings providing the localization for all maneuvers
keywords: {...}, // map of strings providing the localization for all keywords
durations: {...} // map of strings providing the localization for all durations
}
getLanguage(pLanguageCode) → {string|false}
returns a JSON string with the targeted localization.
can be used as a template for adding a new language using getLanguage('default')
Parameters:
Name | Type | Description |
---|---|---|
pLanguageCode |
string | the targeted language code |
Returns:
- Type
- string | false
getLanguageCodes() → {Array.<string>}
returns an array of supported language codes
Returns:
- Type
- Array.<string>
setFloors(floors)
set floor names
Parameters:
Name | Type | Description |
---|---|---|
floors |
Json | object describing the names of floors |
- Since:
- 1.14.0
Example
// floors must have the form
{
floor_B1-00: {
name: 'Floor 1'
},
B2-UL02: {
name: 'Floor 2'
},
...
}
translateInstructions(pNavigation, pLanguageStringopt)
translates all the instructions in pNavigation.instructions, augmenting each instruction with .brief, .detailed, .duration, .durationInSeconds
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
pNavigation |
Array | object describing the navigation and containing the array of instructions | ||
pLanguageString |
string |
<optional> |
'en' | language string like 'en' or 'fr', must be in cLanguageMap, defaults to 'en' if not found. |
- Since:
- 1.7.17 updated signature with mergeFloorChangeInstructions
updateDurationForLanguage(pDuration, pLanguageCode, pDurationString) → {boolean}
updates the localized string for a given duration in a given language
Parameters:
Name | Type | Description |
---|---|---|
pDuration |
string | string describing the duration type |
pLanguageCode |
string | short string describing the targeted language |
pDurationString |
string | new localized string for duration |
Returns:
- Type
- boolean
updateKeywordForLanguage(pKeyword, pLanguageCode, pKeywordString) → {boolean}
updates the localized string for a given keyword in a given language
Parameters:
Name | Type | Description |
---|---|---|
pKeyword |
string | string describing the keyword type |
pLanguageCode |
string | short string describing the targeted language |
pKeywordString |
string | new localized string for keyword |
Returns:
- Type
- boolean
updateManeuverForLanguage(pManeuver, pLanguageCode, pManeuverString) → {boolean}
updates the localized string for a given maneuver in a given language
Parameters:
Name | Type | Description |
---|---|---|
pManeuver |
string | string describing the maneuver type |
pLanguageCode |
string | short string describing the targeted language |
pManeuverString |
string | new localized string for maneuver |
Returns:
- Type
- boolean
updateNextManeuverForLanguage(pManeuver, pLanguageCode, pManeuverString) → {boolean}
updates the localized string for a given next maneuver (maneuver following another) in a given language
Parameters:
Name | Type | Description |
---|---|---|
pManeuver |
string | string describing the maneuver type |
pLanguageCode |
string | short string describing the targeted language |
pManeuverString |
string | new localized string for next maneuver |
Returns:
- Type
- boolean