Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express and i18n #3396

Open
michaelpastushkov opened this issue Oct 28, 2022 · 0 comments
Open

Express and i18n #3396

michaelpastushkov opened this issue Oct 28, 2022 · 0 comments

Comments

@michaelpastushkov
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant