Hi,

One way to do this is (indeed) to use seperate translations files in _javascript_.
Create _javascript_ objects and use them normally. Then apply all the translation strings to the prototype of the objects.
Include the necessary (language specific) file -after- the file with the object and things should be working.


MyObject.js
MyObject = function() {
    // constructor
}
MyObject.prototype = {
    sayHello: function() {
        alert(this.il8n.hello);
    }
}

EN.js
MyObject.prototype.il8n = {
    hello: 'hello world'
}

NL.js
MyObject.prototype.il8n = {
    hello: 'hallo wereld'
}

Consuming code:
var foo = new MyObject();
foo.sayHello();

Regards,
Rocco


!0H0 !B0<5=:>28[ wrote:
Hi. 

I'm thinking about best way to translate js files. 

In my previous project, I use to have server side generated js file for translation, looked like 

var STR1 = <?= $this->translate('str.') ?>; 
var STR2 = <?= $this->translate('str2.') ?>; 
// ... 

But is this really required, maybe writing manual this files and then just include one depending on lang settings, for better performances, but, this one can be cached also if you mess with headers a bit. 

How do you handle this? 

Regards, 
Sasa Stamenkovic.


Reply via email to