File tree Expand file tree Collapse file tree 2 files changed +14
-17
lines changed Expand file tree Collapse file tree 2 files changed +14
-17
lines changed Original file line number Diff line number Diff line change @@ -395,6 +395,17 @@ export function getResolveRoutes(
395
395
normalized = normalizers . postponed . normalize ( normalized , true )
396
396
}
397
397
398
+ if ( config . i18n ) {
399
+ const curLocaleResult = normalizeLocalePath (
400
+ normalized ,
401
+ config . i18n . locales
402
+ )
403
+
404
+ if ( curLocaleResult . detectedLocale ) {
405
+ parsedUrl . query . __nextLocale = curLocaleResult . detectedLocale
406
+ }
407
+ }
408
+
398
409
// If we updated the pathname, and it had a base path, re-add the
399
410
// base path.
400
411
if ( updated ) {
Original file line number Diff line number Diff line change @@ -17,17 +17,8 @@ export function normalizeLocalePath(
17
17
locales ?: string [ ]
18
18
) : PathLocale {
19
19
let detectedLocale : string | undefined
20
- const isDataRoute = pathname . startsWith ( '/_next/data' )
21
-
22
- // Create a pathname for locale detection, removing /_next/data/[buildId] if present
23
- // This is because locale detection relies on path splitting and so the first part
24
- // should be the locale.
25
- const pathNameNoDataPrefix = isDataRoute
26
- ? pathname . replace ( / ^ \/ _ n e x t \/ d a t a \/ [ ^ / ] + / , '' )
27
- : pathname
28
-
29
- // Split the path for locale detection
30
- const pathnameParts = pathNameNoDataPrefix . split ( '/' )
20
+ // first item will be empty string from splitting at first char
21
+ const pathnameParts = pathname . split ( '/' )
31
22
32
23
; ( locales || [ ] ) . some ( ( locale ) => {
33
24
if (
@@ -36,17 +27,12 @@ export function normalizeLocalePath(
36
27
) {
37
28
detectedLocale = locale
38
29
pathnameParts . splice ( 1 , 1 )
30
+ pathname = pathnameParts . join ( '/' ) || '/'
39
31
return true
40
32
}
41
33
return false
42
34
} )
43
35
44
- // For non-data routes, we return the path with the locale stripped out.
45
- // For data routes, we keep the path as is, since we only want to extract the locale.
46
- if ( detectedLocale && ! isDataRoute ) {
47
- pathname = pathnameParts . join ( '/' ) || '/'
48
- }
49
-
50
36
return {
51
37
pathname,
52
38
detectedLocale,
You can’t perform that action at this time.
0 commit comments