astro-loader-i18n
Version:
An Astro content loader for i18n files and folder structures.
31 lines (30 loc) • 1.38 kB
TypeScript
type Segments = Record<string, string | undefined>;
export type SegmentTranslations = Record<string, Segments>;
type RouteSegment = {
spread: boolean;
param: boolean;
value: string;
};
type RoutePattern = RouteSegment[];
/**
* Parses a route pattern into an array of route segments.
*
* @param routePattern is a string that templates the a route (e.g. /[...locale]/blog/[slug])
*/
export declare function parseRoutePattern(routePattern: string): RoutePattern;
/**
* Constructs a full path by resolving a base path with a route pattern and corresponding segment values.
*
* @param routePattern - An array of route segments that define the structure of the route.
* Each segment can either be a static value or a parameter.
* @param segmentValues - An object mapping parameter names to their corresponding values.
* These values are used to replace parameterized segments in the route pattern.
* @param basePath - The base path to resolve the constructed route against.
*
* @returns The resolved path as a string.
*
* @throws {Error} If a required segment value for a parameterized route segment is missing
* and the segment is not marked as a spread segment.
*/
export declare function buildPath(routePattern: RoutePattern, segmentValues: Segments, basePath: string): string;
export {};