11import { 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" ;
33import { getEntry , type CollectionKey , type DataEntryMap } from "astro:content" ;
44import type { ImageMetadata } from "astro" ;
5+ import { parseLocale } from "./i18n" ;
56
67const PROTOCOL_DELIMITER = "://" ;
78
@@ -10,6 +11,13 @@ export const defaultPropsAndParamsOptions = {
1011 segmentTranslations : C . SEGMENT_TRANSLATIONS ,
1112} ;
1213
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+
1321export const resolvePath = ( ...path : Array < string | number | undefined > ) => {
1422 return originalResolvePath ( import . meta. env . BASE_URL , ...path ) ;
1523} ;
@@ -40,8 +48,9 @@ export const convertReferenceToPath = async (path: string) => {
4048 if ( typeof entry . data . path !== "string" ) throw new Error ( "Entry title is not a string" ) ;
4149
4250 const localeSlug = entry . data . locale === C . DEFAULT_LOCALE ? undefined : entry . data . locale ;
51+ const contentPath = replaceSegmentsInPath ( entry . data . contentPath , parseLocale ( entry . data . locale ) ) ;
4352
44- return originalResolvePath ( localeSlug , entry . data . contentPath , entry . data . path ) ;
53+ return originalResolvePath ( localeSlug , contentPath , entry . data . path ) ;
4554} ;
4655
4756type NavigationItems = DataEntryMap [ "navigation" ] [ "data" ] [ "data" ] [ "items" ] ;
0 commit comments