[req|res].setLocale() doesn't change template locale
See original GitHub issueapp.use(i18n.init)
sets res.locals.locale
so that the template helpers can get the current language. However, calling res.setLocale()
doesn’t update this property, so the final page language doesn’t get changed.
// First Request:
app.use(i18n.init); // locale=en, res.locals.locale=en
app.use(function(req, res, next) {
res.setLocale('ja'); // locale=ja, res.locals.locale=en
res.render('some-template'); // template i18n helpers use locals.locale,
// so page is still in english
});
// Second Request:
app.use(i18n.init); // locale = ja, res.locals.locale=ja
// ...
I’m not sure what the right fix is here (or even if you consider this bug), but I thought I’d open this up to start a discussion.
Issue Analytics
- State:
- Created 9 years ago
- Comments:12 (8 by maintainers)
Top Results From Across the Web
setlocale() doesn't read from bindtextdomain() dir C++
The setlocale() function checks the environment, when you call it with an empty string as the second argument. That is then called the...
Read more >Cannot set LC_CTYPE to default locale: No such file or directory
You have two ways to remedy this: either you change, what is requested or you add the requested locale to the remote system...
Read more >perllocale - Perl locale handling (internationalization and ...
If setlocale() fails for some reason (for example, an attempt to set to a locale unknown to the system), the locale for the...
Read more >Documentation: 15: 24.1. Locale Support - PostgreSQL
You can use different settings for different databases, but once a database is created, you cannot change them for that database anymore. LC_COLLATE...
Read more >How to change system locale on RHEL7?
Configuring locales that are set at login requires some knowledge of different configuration files. What changes you will need to make ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had same/similar issue. I solved it by manually setting res.locals.language to same locale as in req.setLocale fnc.
Hope it helps.
Yea sure, it’s small enough to include here:
This is slightly different behavior than my application (not sure where my
undefined
s are coming from) but it looks like that same hbs template helper problem would be occurring here as well