rsnext/packages/next/next-server/lib/i18n/normalize-locale-path.ts
JJ Kasper 1eeac4f99b
Make sure locale detecting is case-insensitive (#17757)
Follow-up to https://github.com/vercel/next.js/pull/17370 this makes sure the locale detection is case-insensitive.
2020-10-11 20:40:47 +00:00

26 lines
598 B
TypeScript

export function normalizeLocalePath(
pathname: string,
locales?: string[]
): {
detectedLocale?: string
pathname: string
} {
let detectedLocale: string | undefined
// first item will be empty string from splitting at first char
const pathnameParts = pathname.split('/')
;(locales || []).some((locale) => {
if (pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
detectedLocale = locale
pathnameParts.splice(1, 1)
pathname = pathnameParts.join('/') || '/'
return true
}
return false
})
return {
pathname,
detectedLocale,
}
}