Skip to content

Commit

Permalink
feat: change invalid language codes to default lang
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jul 24, 2020
1 parent a294e1c commit 3761f05
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/middleware/headers.js
Expand Up @@ -65,10 +65,18 @@ module.exports = function (middleware) {
});

middleware.autoLocale = helpers.try(async function autoLocale(req, res, next) {
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang || req.query.lang) {
let langs;
if (req.query.lang) {
langs = await listCodes();
if (!langs.includes(req.query.lang)) {
req.query.lang = meta.config.defaultLang;
}
return next();
}
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
return next();
}
const langs = await listCodes();
langs = await listCodes();
const lang = req.acceptsLanguages(langs);
if (!lang) {
return next();
Expand Down

0 comments on commit 3761f05

Please sign in to comment.