You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Better support for i18n is needed inside pug templates. For now I found the solution but it's a bit complex and confusing. I though pug processor is one of the natively supported engines for i18n.
// Module level
const pug = require('pug');
const func = pug.compileFile('pug/test.pug');
function foo(req, res) {
let msg = res.__('Hello');
let ins = func({ message: msg, : res. }); // << I have to add this to every render request
res.end(ins);
}
Input Pug
p #{msg}
p #{__('Hello')}
Expected HTML
Localised output (based on browser locale)
Actual HTML
Localised output (based on browser locale)
I finally made it work, but there should be an easier way to do it.
The text was updated successfully, but these errors were encountered:
Better support for i18n is needed inside pug templates. For now I found the solution but it's a bit complex and confusing. I though pug processor is one of the natively supported engines for i18n.
Pug Version: "^3.0.2",
Node Version: v14.15.4
Input JavaScript Values
// server level
app.use(function(req, res, next) {
// express helper for natively supported engines
i18n.init(req, res);
res.locals.__ = res.__ = function() {
return i18n.__.apply(req, arguments);
};
next();
});
// Module level
const pug = require('pug');
const func = pug.compileFile('pug/test.pug');
function foo(req, res) {
let msg = res.__('Hello');
let ins = func({ message: msg, : res. }); // << I have to add this to every render request
res.end(ins);
}
Input Pug
p #{msg}
p #{__('Hello')}
Expected HTML
Localised output (based on browser locale)
Actual HTML
Localised output (based on browser locale)
I finally made it work, but there should be an easier way to do it.
The text was updated successfully, but these errors were encountered: