UNPKG

@gulibs/react-autoroutes-client

Version:

Client-side utilities for React auto routes

114 lines 3.59 kB
/** * 国际化资源加载工具 - 对标 @gulibs/vite-plugin-i18n 优化版 */ /** * 资源加载器配置接口 - 与 vite-plugin-i18n 兼容 */ export interface I18nLoaderConfig { /** 翻译资源基础路径 */ basePath?: string; /** 支持的文件扩展名 */ extensions?: string[]; /** 语言代码提取模式 */ localePattern?: 'directory' | 'filename'; /** 默认语言代码 */ defaultLocale?: string; /** 缓存时间 (毫秒) */ cacheTime?: number; /** 是否启用缓存 */ cache?: boolean; /** 是否启用调试模式 */ debug?: boolean; /** 加载回调 */ onLoad?: (locale: string, data: Record<string, any>) => void; /** 错误回调 */ onError?: (locale: string, error: Error) => void; /** 自定义获取翻译资源函数 */ fetchResources?: (locale: string, path: string) => Promise<Record<string, any>>; } /** * 资源加载器接口 - 与 vite-plugin-i18n 生成的接口兼容 */ export interface I18nResourceLoader { /** 加载指定语言的资源 */ loadResources: (locale: string) => Promise<Record<string, any>>; /** 预加载多个语言的资源 */ preloadResources: (locales: string[]) => Promise<Record<string, Record<string, any>>>; /** 清除缓存 */ clearCache: (locale?: string) => void; /** 获取配置 */ getConfig: () => I18nLoaderConfig; /** 获取所有可用的键 */ getAvailableKeys?: () => string[]; /** 检查键是否存在 */ hasKey?: (key: string) => boolean; /** 获取命名空间资源 */ getNamespaceResources?: (locale: string, namespace: string) => Record<string, any> | undefined; } /** * 虚拟模块加载器 - 优先使用 vite-plugin-i18n 生成的资源 */ export declare class ViteI18nLoader implements I18nResourceLoader { private config; private cache; private virtualModuleResources?; private virtualModuleKeys?; private virtualModuleSupportedLocales?; constructor(config?: I18nLoaderConfig); /** * 初始化虚拟模块资源 */ private initVirtualModule; /** * 加载指定语言的翻译资源 */ loadResources(locale: string): Promise<Record<string, any>>; /** * 动态加载资源(当虚拟模块不可用时的回退方案) */ private dynamicLoadResources; /** * 预加载多个语言的翻译资源 */ preloadResources(locales: string[]): Promise<Record<string, Record<string, any>>>; /** * 清除资源缓存 */ clearCache(locale?: string): void; /** * 获取配置 */ getConfig(): I18nLoaderConfig; /** * 获取所有可用的键(来自虚拟模块) */ getAvailableKeys(): string[]; /** * 检查键是否存在 */ hasKey(key: string): boolean; /** * 获取命名空间资源 */ getNamespaceResources(locale: string, namespace: string): Record<string, any> | undefined; /** * 获取支持的语言列表 */ getSupportedLocales(): string[]; /** * 检查是否使用虚拟模块 */ isUsingVirtualModule(): boolean; } /** * 创建优化的资源加载器 */ export declare function createI18nLoader(config?: I18nLoaderConfig): I18nResourceLoader; /** * 创建兼容旧版的资源加载器 * @deprecated 使用 createI18nLoader 替代 */ export declare function createResourceLoader(config?: I18nLoaderConfig): I18nResourceLoader & { loadFromImportGlob: () => Promise<Record<string, any>>; }; //# sourceMappingURL=i18n-loader.d.ts.map