1eeac4f99b
Follow-up to https://github.com/vercel/next.js/pull/17370 this makes sure the locale detection is case-insensitive.
26 lines
598 B
TypeScript
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,
|
|
}
|
|
}
|