Skip to content

Commit bfd3f54

Browse files
committed
chore: revert red herring
1 parent dccecf9 commit bfd3f54

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

edge-runtime/lib/util.ts

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,18 @@ export interface PathLocale {
6060
*/
6161
export function normalizeLocalePath(pathname: string, locales?: string[]): PathLocale {
6262
let detectedLocale: string | undefined
63-
64-
// normalize the locales to lowercase
65-
const normalizedLocales = locales?.map((loc) => loc.toLowerCase())
66-
67-
// split the pathname into parts, removing the leading slash
68-
const pathnameParts = pathname.substring(1).split('/')
69-
70-
// split the first part of the pathname to check if it's a locale
71-
const localeParts = pathnameParts[0].toLowerCase().split('-')
72-
73-
// check if the first part of the pathname is a locale
74-
// by matching the given locales, with decreasing specificity
75-
for (let i = localeParts.length; i > 0; i--) {
76-
const localePart = localeParts.slice(0, i).join('-')
77-
if (normalizedLocales?.includes(localePart)) {
78-
detectedLocale = localeParts.join('-')
79-
pathname = `/${pathnameParts.slice(1).join('/')}`
80-
break
63+
// first item will be empty string from splitting at first char
64+
const pathnameParts = pathname.split('/')
65+
66+
;(locales || []).some((locale) => {
67+
if (pathnameParts[1] && pathnameParts[1].toLowerCase() === locale.toLowerCase()) {
68+
detectedLocale = locale
69+
pathnameParts.splice(1, 1)
70+
pathname = pathnameParts.join('/')
71+
return true
8172
}
82-
}
83-
73+
return false
74+
})
8475
return {
8576
pathname,
8677
detectedLocale,

0 commit comments

Comments
 (0)