зеркало из https://github.com/github/docs.git
fix: detect language for _next/data requests (#21696)
This commit is contained in:
Родитель
cff6a8ade8
Коммит
06f1d3de73
|
@ -35,12 +35,14 @@ function getUserLanguage(browserLanguages) {
|
|||
}
|
||||
|
||||
export default function detectLanguage(req, res, next) {
|
||||
// determine language code from first part of URL, or default to English
|
||||
// determine language code from the URL, or default to English
|
||||
// /en/articles/foo
|
||||
// ^^
|
||||
const firstPartOfPath = req.path.split('/')[1]
|
||||
// /_next/data/development/en/articles/foo
|
||||
// ^^
|
||||
const maybeLanguage = req.path.split('/')[req.path.startsWith('/_next/data/') ? 4 : 1]
|
||||
|
||||
req.language = languageCodes.includes(firstPartOfPath) ? firstPartOfPath : 'en'
|
||||
req.language = languageCodes.includes(maybeLanguage) ? maybeLanguage : 'en'
|
||||
// Detecting browser language by user preference
|
||||
const browserLanguages = parser.parse(req.headers['accept-language'])
|
||||
req.userLanguage = getUserLanguage(browserLanguages)
|
||||
|
|
Загрузка…
Ссылка в новой задаче