1
1
import { createI18nCollection , i18nPropsAndParams , resolvePath as originalResolvePath } from "astro-loader-i18n" ;
2
- import { C , localeSlugs } from "../site.config" ;
2
+ import { C , localeSlugs , type Locale } from "../site.config" ;
3
3
import { getEntry , type CollectionKey , type DataEntryMap } from "astro:content" ;
4
4
import type { ImageMetadata } from "astro" ;
5
+ import { parseLocale } from "./i18n" ;
5
6
6
7
const PROTOCOL_DELIMITER = "://" ;
7
8
@@ -10,6 +11,13 @@ export const defaultPropsAndParamsOptions = {
10
11
segmentTranslations : C . SEGMENT_TRANSLATIONS ,
11
12
} ;
12
13
14
+ export const replaceSegmentsInPath = ( path : string , locale : Locale ) => {
15
+ Object . entries ( C . SEGMENT_TRANSLATIONS [ locale ] ) . forEach ( ( [ key , value ] ) => {
16
+ path = path . replace ( key , value ) ;
17
+ } ) ;
18
+ return path ;
19
+ } ;
20
+
13
21
export const resolvePath = ( ...path : Array < string | number | undefined > ) => {
14
22
return originalResolvePath ( import . meta. env . BASE_URL , ...path ) ;
15
23
} ;
@@ -40,8 +48,9 @@ export const convertReferenceToPath = async (path: string) => {
40
48
if ( typeof entry . data . path !== "string" ) throw new Error ( "Entry title is not a string" ) ;
41
49
42
50
const localeSlug = entry . data . locale === C . DEFAULT_LOCALE ? undefined : entry . data . locale ;
51
+ const contentPath = replaceSegmentsInPath ( entry . data . contentPath , parseLocale ( entry . data . locale ) ) ;
43
52
44
- return originalResolvePath ( localeSlug , entry . data . contentPath , entry . data . path ) ;
53
+ return originalResolvePath ( localeSlug , contentPath , entry . data . path ) ;
45
54
} ;
46
55
47
56
type NavigationItems = DataEntryMap [ "navigation" ] [ "data" ] [ "data" ] [ "items" ] ;
0 commit comments