Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use i18n variables in Pug template files?

I'm new to Node.js and I'm trying to learn how to use i18n in my Pug template and could not find my answer anywhere.

The documentation says

in your templates (depending on your template engine)

<%= __('Hello') %>

${__('Hello')}

So far I tried (in my pug template)

${__('Hello')}

__('Hello')

None of those syntax is working, what is the correct one to use ?

I know it is well configure because when using

i18n.__('Hello')

And sending it to my template in a variable it is working.

like image 511
Sam Bellerose Avatar asked Dec 15 '22 00:12

Sam Bellerose


1 Answers

Answer was right in the documentation, only needed to add this to my configuration.

app.use(function(req, res, next) {
    // express helper for natively supported engines
    res.locals.__ = res.__ = function() {
        return i18n.__.apply(req, arguments);
    };

    next();
});
like image 70
Sam Bellerose Avatar answered Dec 21 '22 11:12

Sam Bellerose