Most modules use Accept-Language
so I can't find any that use the path like this that you might be able to use. So you'll need to define your own middleware that initializes before everything else. Express's Router
doesn't really help for your usecase.
app.use(function(req, res, next){
var match = req.url.match(/^\/([A-Z]{2})([\/\?].*)?$/i);
if (match){
req.lang = match[1];
req.url = match[2] || '/';
}
next();
});
Now you can use req.lang
in your routes or other middleware to configure your translation logic and since we have rewritten the URL, later logic will not know that there is a language param.