mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 08:36:12 +01:00
feat: change invalid language codes to default lang
This commit is contained in:
@@ -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();
|
||||
}
|
||||
const langs = await listCodes();
|
||||
if (parseInt(req.uid, 10) > 0 || !meta.config.autoDetectLang) {
|
||||
return next();
|
||||
}
|
||||
langs = await listCodes();
|
||||
const lang = req.acceptsLanguages(langs);
|
||||
if (!lang) {
|
||||
return next();
|
||||
|
||||
Reference in New Issue
Block a user