I\'m looking to use hogan.js to create html form a template in the browser. I\'ve read that hogan supports i18n, but I can\'t find an example of how this works. How do you
It is actually easy to combine this with other internationalisation approaches. We are using jquery-i18n-properties, which is a jQuery plugin that supports the use of .properties files, which are compatible to Java.
The framework tries to download a file called Messages.properties and depending on the browsers language fo example Messages_en.properties and Messages_en_US.properties. This allows to build a hierarchy of translations very quickly.
So slightly changing the example of slashnick and using hogan/mustache, I write:
var template = "{{#i18n}}Name{{/i18n}}: {{username}}",
context = {
username: "Jean Luc",
i18n: function (i18nKey) {return jQuery.i18n.prop(key);}
};
// Init i18n
jQuery.i18n.properties(
{
name:'Messages',
path:'some/path',
mode : 'map'
});
Hogan.compile(template).render(context);
Messages.properties File:
Name = Name
Messages_fr.properties File:
Name = nom
I do not really see the advantage of using the special mustache version with looks up a global function (performance maybe?).