i18n with Hogan.js

885 Views Asked by At

I just started with node.js and express.js. As server-side templating framework I picked Hogan.js. I am now trying to find out how I can do i18n with Hogan.js, and I found some information in this post. It seems that you always have to pass in the i18n function together with the context of the view. Is it possible to configure this or set this up at a single place in the application? It seems very cumbersome if I have to do this for each and every view separately. Thanks!

2

There are 2 best solutions below

1
Arnaud Rinquin On

You could take a look at Express-lingua which seems to perfectly match your needs.

0
Paul Scheltema On

wrap the render function of hogan if you must

var origional = Hogan.template.prototype.render;
Hogan.template.prototype.render = function (context, partials, indent) {
    context['i18n'] = function () {
        return function () {
            return 'i18n';
        };
    };
    return origional.call(this, context, partials, indent);
};