Answer the question
In order to leave comments, you need to log in
How to make the function more extensible in the future?
How to make the function simpler and more extensible in the future?
var langs, lang, words;
module.exports = function (req, res, next) {
if(req.session.lang) {
lang = req.session.lang
} else {
langs = req.headers["accept-language"];
lang = langs[0] + langs[1];
}
res.locals = require('./langs/' + lang + '.json')
next();
}
зарание спасибо
Answer the question
In order to leave comments, you need to log in
1. How did you parse req.headers so quickly, there could be something like this, for example:
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
Accept-Language: da, en-gb;q=0.8, en;q=0.7
Accept-Language: cmn-Hans-CN
Accept-Language: i-enochian
Accept-Language: cel-gaulish
Accept-Language: *
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question