const langs = ['en', 'ru', 'de', 'fr'];
const langsRE = new RegExp(`/(${langs.join('|')})(?:/|$)`, 'i');
app.set('view engine', 'pug');
const router = express.Router();
router.get('/', (req, res) => {
res.render('index', res.locals);
});
router.get('/about', (req, res) => {
res.render('about', res.locals);
});
app.use((req, res, next) => {
let lang = 'en';
const found = langsRE.exec(req.url);
if (found) {
lang = found[1];
req.url = req.url.replace(langsRE, '/');
}
Object.assign(res.locals, {lang, __: app.locales[lang]});
next();
});
app.use(router);