1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/middleware/detect-language.js
Vanessa Yuen 3df90fc9b8 Hello git history spelunker!
Are you looking for something? Here is all of the GitHub Docs history in one single commit. Enjoy! 🎉
2020-09-27 14:10:11 +02:00

13 lines
385 B
JavaScript

const languageCodes = Object.keys(require('../lib/languages'))
// determine language code from first part of URL, or default to English
module.exports = async function detectLanguage (req, res, next) {
// /en/articles/foo
// ^^
const firstPartOfPath = req.path.split('/')[1]
req.language = languageCodes.includes(firstPartOfPath) ? firstPartOfPath : 'en'
return next()
}