[GIS] How to localize leaflet routing

javascriptleafletrouting

Leaflet-routing: http://www.liedman.net/leaflet-routing-machine/

If you initialize the L.Routing.control like this:

var router = new L.Routing.control({
    waypoints: [L.latLng(57.74, 11.94), L.latLng(57.6792, 11.949)],
    language: 'pt' // here's the magic
}).addTo(map);

It appears translated on the page.

enter image description here

but when I access the instructions in the 'router' object: router._routes[0].instructions[0] it returns something like this:

router._routes[0].instructions[0] = {
    direction: "E",
    distance: 13041.6,
    exit: undefined,
    index: 0,
    mode: "driving",
    modifier: undefined,
    road: "",
    time: 860.2,
    type: "Head"
}

How can I get the translation formatted like in the interface?

Best Answer

Find out.

This doesn't work for some reason:

var l = new L.Routing.Formatter('pt');
var text = l.formatInstruction(router._routes[0].instructions[0], 0);
var distance = l.formatDistance(router._routes[0].instructions[0].distance);

but this do:

var text = router._formatter.formatInstruction(router._routes[0].instructions[0], 0);
var distance = router._formatter.formatDistance(router._routes[0].instructions[0].distance);

You have for loop through all the instructions and mount the strings yourself but is better than nothing.