@@ -76,39 +76,39 @@ export const Route = createRootRoute({
7676If you don't want to miss any translated path, you can create a ` createTranslatedPathnames ` function and pass it to the vite plugin.
7777
7878``` ts
79- import { Locale } from " @/paraglide/runtime" ;
80- import { FileRoutesByTo } from " ../routeTree.gen" ;
79+ import { Locale } from ' @/paraglide/runtime'
80+ import { FileRoutesByTo } from ' ../routeTree.gen'
8181
82- type RoutePath = keyof FileRoutesByTo ;
82+ type RoutePath = keyof FileRoutesByTo
8383
84- const excludedPaths = [" admin" , " docs" , " api" ] as const ;
84+ const excludedPaths = [' admin' , ' docs' , ' api' ] as const
8585
8686type PublicRoutePath = Exclude <
8787 RoutePath ,
8888 ` ${string }${(typeof excludedPaths )[number ]}${string } `
89- >;
89+ >
9090
9191type TranslatedPathname = {
92- pattern: string ;
93- localized: Array <[Locale , string ]>;
94- };
92+ pattern: string
93+ localized: Array <[Locale , string ]>
94+ }
9595
9696function toUrlPattern(path : string ) {
9797 return (
9898 path
9999 // catch-all
100- .replace (/ \/\$ $ / , " /:path(.*)?" )
100+ .replace (/ \/\$ $ / , ' /:path(.*)?' )
101101 // optional parameters: {-$param}
102- .replace (/ \{ -\$ ([a-zA-Z0-9 _] + )\} / g , " :$1?" )
102+ .replace (/ \{ -\$ ([a-zA-Z0-9 _] + )\} / g , ' :$1?' )
103103 // named parameters: $param
104- .replace (/ \$ ([a-zA-Z0-9 _] + )/ g , " :$1" )
104+ .replace (/ \$ ([a-zA-Z0-9 _] + )/ g , ' :$1' )
105105 // remove trailing slash
106- .replace (/ \/ + $ / , " " )
107- );
106+ .replace (/ \/ + $ / , ' ' )
107+ )
108108}
109109
110110function createTranslatedPathnames(
111- input : Record <PublicRoutePath , Record <Locale , string >>
111+ input : Record <PublicRoutePath , Record <Locale , string >>,
112112): TranslatedPathname [] {
113113 return Object .entries (input ).map (([pattern , locales ]) => ({
114114 pattern: toUrlPattern (pattern ),
@@ -117,21 +117,21 @@ function createTranslatedPathnames(
117117 [locale as Locale , ` /${locale }${toUrlPattern (path )} ` ] satisfies [
118118 Locale ,
119119 string ,
120- ]
120+ ],
121121 ),
122- }));
122+ }))
123123}
124124
125125export const translatedPathnames = createTranslatedPathnames ({
126- " / " : {
127- en: " / " ,
128- de: " / " ,
126+ ' / ' : {
127+ en: ' / ' ,
128+ de: ' / ' ,
129129 },
130- " /about" : {
131- en: " /about" ,
132- de: " /ueber" ,
130+ ' /about' : {
131+ en: ' /about' ,
132+ de: ' /ueber' ,
133133 },
134- });
134+ })
135135```
136136
137137And import into the Paraglide Vite plguin.
0 commit comments