Localization of tooltip in api 2.0

741
2
07-16-2010 06:37 AM
kristoffersnabb
New Contributor
Hello,

The javascript api has some very nice improvements, like the tooltip that appears when drawing a polygon or polyline.

But I did not find any way to localize the tooltip, and djConfig.local does not seem to work:

var djConfig = {
     ...
     locale: 'sv',
}

Is there a list somewhere which locales the tooltip supports or how to change the locale if not through djConfig?
0 Kudos
2 Replies
kristoffersnabb
New Contributor
Well there is no answer yet, so I post my workaround for the interrested (but I hope there is a better solution around from Esri soon).

I made a function which translates the innerHTML of a node:
function translate(node) {

        if(node === undefined) {
            return;
            }
        if(node.innerHTML === "Click to add a point") {
            if(djConfig.locale === "sv") {
                node.innerHTML = "Klicka på kartan för att lägga till platsen";
                }
            else if(djConfig.locale === "fi") {
                node.innerHTML = "Lisää paikka napsauttamalla karttaa";
                }
            }
        else if(node.innerHTML === "Click to start drawing") {
            console.log(djConfig.locale);
            if(djConfig.locale === "sv") {
                node.innerHTML = "Klicka på kartan för att börja rita";
                }
            else if(djConfig.locale === "fi") {
                node.innerHTML = "Aloita piirtäminen napsauttamalla karttaa";
                }
            }
        else if(node.innerHTML === "Click to continue drawing") {
            console.log(djConfig.locale);
            if(djConfig.locale === "sv") {
                node.innerHTML = "Klicka på kartan för att fortsätta rita";
                }
            else if(djConfig.locale === "fi") {
                node.innerHTML = "Napsauta karttaa jatkaaksesi piirtoa";
                }
            }
        else if(node.innerHTML === "Double-click to complete") {
            console.log(djConfig.locale);
            if(djConfig.locale === "sv") {
                node.innerHTML = "Sluta rita med en dubbelklick";
                }
            else if(djConfig.locale === "fi") {
                node.innerHTML = "Lopeta piirto kaksoisklikkauksella";
                }
            }
            
    }

And I connect an onClick event to the map:
translateEvent = dojo.connect(map, "onClick", function(event) {
    var tooltip = dojo.query("div.tooltip")[0];
    translate(tooltip);
});
0 Kudos
MarcelKleinmann
New Contributor
Well done ksnabb,

I gave your idea a try.

Only I changed your
dojo.connect(map, "onClick", function(event)
to
dojo.connect(map, "onMouseOver", function(event)
as otherwise the translate function didn't get called.

Now it's doing fine, except for one thing: when I just clicked and didn't move the mouse yet, the original english tooltip is being displayed! Then I move the mouse again and it switches back to the (right) translated version.

For a workaround I copied the listener "translateEvent" to have it in the code twice. The first I made "onMouseMove" and the second "translateEvent1" I made "onClick". Still no solution - same behaviour like I described above.

Any idea?

Cheers
0 Kudos