Mark
Mark

Reputation: 5028

i18nextify doesn't translate in javascript function

Following this example I was able to add locales to my application and to translate strings in html/Jade.

For example, given this translation.json file:

{
    "test": "prova"
}

I can put it in my Jade page:

label test

Right now I'm using the same configuration options of the link above. What doesn't work is the translation in a javascript function, example:

script(type="text/javascript").
    require([
        "dojo/ready",
        "dojo/dom",
        "dojo/on",
        "dojo/request/xhr",
        "dojo/domReady!"
    ], function (ready, dom, on, xhr) {
        console.log("dom ready");
        console.log("test");
    });

it doesn't translate the string "test" to "prova" like it does few lines above in the html code. In the github example the author does something similar:

var t = document.createTextNode("CLICK ME");

where "CLICK ME" is a string available in the translation file. Hence I guessed it should translate also my

console.log("test");

What am I missing?

Upvotes: 0

Views: 194

Answers (1)

jamuhl
jamuhl

Reputation: 4498

The sample does work as we append that node to the dom -> i18nextify used virtualdom implementation and automatically parses and translate dom content.

You can use the underlying i18next instance to translate javascript content directly.

console.log(i18nextify.i18next.t('dom ready')); -> for docs see http://i18next.com

Upvotes: 1

Related Questions