Does any one knows an example or could explain here how node.js and express would have to route for a multilanguage site? I'm using i18n-node for translation and folder like routing ( /es/, /de/ , etc ) for different languages. This all are static routes but I also have routes like apiRoutes.route('/user/profile') using 'app' at the begining ( app.get('/app/user/profile') so please consider this in your answer so is NOT necesary route to : app.get('/es/app/user/profile') .
having 15 routes like this now:
app.get('/terms', function(req, res) {
res.render('terms',{
...
});
});
how it have to be set for routes like:
app.get('/es/terms', function(req, res) {
res.render('terms',{
...
});
});
Should I duplicate this routes and add for example a locale for each like:
app.get('/es/terms', function(req, res) { res.render('terms',{ ... }); });
Or Should do something like:
if cookie['lang'] && cookie['lang'] is in locales // then redirect to /:lang/terms else // show default language in /terms if req.headers["accept-language"] && req.headers["accept-language"] // then redirect to /:lang/terms else //show default language in /terms
Or there is another way I should approach this that follows good practices or is better respecting standards?
Miro's Answer in : How can I get the browser language in node.js (express.js)? says I should use app.all('*', ...
Is this all I need?, ..still, it might have a syntax error or i'm not understanding well this two parts
var rxLocal = /^\/(de|en)/i;
...
app.get(/\/(de|en)\/login/i, routes.login);
thanks in advance