UNPKG

astro-loader-i18n

Version:

An Astro content loader for i18n files and folder structures.

71 lines (70 loc) 2.99 kB
import { I18nLoaderEntry } from '../schemas/i18n-loader-schema'; import { SegmentTranslations } from '../utils/route'; import { CollectionEntry, CollectionKey } from 'astro:content'; /** * Configuration options for internationalization (i18n) routing. * * @template C - The type of the entry used for segment generation. * @property defaultLocale - The default locale to use when none is specified. * @property routePattern - The route pattern string used for matching and generating localized routes. * @property segmentTranslations - An object containing translations for route segments. * @property generateSegments - (Optional) A function that generates a mapping of segment names to their translations for a given entry. * @property localeParamName - (Optional) The name of the parameter used to specify the locale in routes. * @property prefixDefaultLocale - (Optional) Whether to prefix the default locale in generated routes. */ type Config<C> = { defaultLocale: string; routePattern: string; segmentTranslations: SegmentTranslations; generateSegments?: (entry: C) => Record<string, string>; localeParamName?: string; prefixDefaultLocale?: boolean; }; /** * Processes a collection of entries and generates i18n-related properties and parameters. * * @template C - The type of the collection entries. * @param collection - The collection of entries or an i18n collection. * @param config - The configuration object for i18n processing. * @returns An array of objects containing `params` and `props` for each entry. * @throws {Error} If route segment translations or slug parameters are invalid. */ export declare function i18nPropsAndParams<C extends CollectionEntry<CollectionKey>>(collection: C[] | I18nLoaderEntry[], config: Config<C>): { params: { [x: string]: string | undefined; }; props: C & { data: { locale: string; translationId: string; contentPath: string; basePath: string; }; filePath?: string | undefined; } & { translations: Record<string, string>; translatedPath: string; }; }[]; /** * Processes a collection of entries and generates i18n-related properties. * * @template C - The type of the collection entries. * @param collection - The collection of entries or an i18n collection. * @param config - The configuration object for i18n processing. * @returns An array of objects containing the `props` for each entry. * @throws {Error} If route segment translations or slug parameters are invalid. */ export declare function i18nProps<C extends CollectionEntry<CollectionKey>>(collection: C[] | I18nLoaderEntry[], config: Config<C>): (C & { data: { locale: string; translationId: string; contentPath: string; basePath: string; }; filePath?: string | undefined; } & { translations: Record<string, string>; translatedPath: string; })[]; export {};