Closed Macha-orange closed 3 years ago
Hello,
I have a website with nodejs+express+ejs and I have root langage as a parameter inside url like this :
www.mywebsite.com/en/ www.mywebsite.com/fr/
Here my code :
const i18n = require('i18n') i18n.configure({ locales: ['en', 'fr'], directory: ('./locales') }) app.use(i18n.init) app.use((req, res, next) => { i18n.setLocale(req, localeTag), next(); });
With express here the parameter :
app.get('/:lang/', function (req, res) { localeTag = req.params.lang; // code here
First I thought that it was no working but what I need to do to change language is quite annoying :
i'm here : www.mywebsite.com/en/ so the site is in english.
I change my url to www.mywebsite.com/fr/ but the site is again in english.
I'm at www.mywebsite.com/fr/ still in english, then when I do 1 refresh, everything is translated.
Same thing if I go the other way. Always need to do a refresh ?
As written in #463 the example should guide you https://github.com/mashpie/i18n-express-hbs-prefix
I’ll close this in favor of your other issue.
Hello,
I have a website with nodejs+express+ejs and I have root langage as a parameter inside url like this :
www.mywebsite.com/en/ www.mywebsite.com/fr/
Here my code :
With express here the parameter :
First I thought that it was no working but what I need to do to change language is quite annoying :
i'm here : www.mywebsite.com/en/ so the site is in english.
I change my url to www.mywebsite.com/fr/ but the site is again in english.
I'm at www.mywebsite.com/fr/ still in english, then when I do 1 refresh, everything is translated.
Same thing if I go the other way. Always need to do a refresh ?