@ui18n/svelte
Version:
🧡 Lightning-fast Svelte internationalization with reactive stores, SvelteKit support, and zero-bundle overhead
115 lines (114 loc) • 3.32 kB
TypeScript
import type { SupportedLanguage, UI18n, TranslationResult } from '@ui18n/core';
/**
* 批量翻译选项
*/
export interface BatchTranslationOptions {
language?: SupportedLanguage;
context?: string;
maxConcurrency?: number;
priority?: 'low' | 'normal' | 'high';
useOptimizer?: boolean;
enableProgressTracking?: boolean;
}
/**
* 实时同步选项
*/
export interface RealTimeSyncOptions {
enableVersionControl?: boolean;
websocketUrl?: string;
sseUrl?: string;
syncMethod?: 'websocket' | 'sse' | 'polling';
}
/**
* 缓存优化选项
*/
export interface CacheOptimizationOptions {
enableAutoCleanup?: boolean;
cleanupInterval?: number;
memoryThreshold?: number;
enablePreloading?: boolean;
preloadLanguages?: string[];
}
/**
* 批量翻译状态
*/
export interface BatchTranslationState {
translations: Record<string, string>;
translationArray: string[];
loading: boolean;
error: string | null;
progress: number;
completedCount: number;
totalCount: number;
failedTexts: string[];
}
/**
* 实时同步状态
*/
export interface RealTimeSyncStatus {
enabled: boolean;
connected: boolean;
method: string;
lastEvent?: number;
syncErrors: number;
}
/**
* 缓存统计
*/
export interface CacheStats {
totalItems: number;
memoryUsageMB: number;
memoryLimitMB: number;
memoryUtilization: number;
hits: number;
misses: number;
hitRate: number;
type: string;
}
/**
* UI18n Store 实例类型
*/
export interface UI18nStoreInstance {
subscribe: any;
setLanguage: (language: SupportedLanguage) => Promise<void>;
translate: (text: string, options?: any) => Promise<string>;
translateBatch: (texts: string[], options?: BatchTranslationOptions) => Promise<TranslationResult[]>;
translateBatchOptimized: (texts: string[], options?: BatchTranslationOptions) => Promise<TranslationResult[]>;
getLanguageDisplayName: (language: SupportedLanguage, displayLanguage?: SupportedLanguage) => string;
detectAndSetSystemLanguage: () => Promise<void>;
searchLanguages: (query: string, availableLanguages: SupportedLanguage[]) => SupportedLanguage[];
connectRealTimeSync: (options?: RealTimeSyncOptions) => Promise<boolean>;
disconnectRealTimeSync: () => void;
manualSync: (language?: SupportedLanguage) => Promise<boolean>;
clearCache: (pattern?: string) => Promise<void>;
optimizeCache: () => Promise<void>;
preloadLanguage: (language: string) => Promise<void>;
getCacheStats: () => CacheStats | null;
getRealTimeSyncStatus: () => RealTimeSyncStatus;
stores: {
currentLanguage: any;
loading: any;
error: any;
batchState: any;
realTimeSyncStatus: any;
cacheStats: any;
syncErrors: any;
};
ui18n: UI18n;
}
/**
* 创建UI18n Store
*/
export declare function createUI18nStore(config: any): UI18nStoreInstance;
/**
* 设置全局UI18n Store
*/
export declare function setGlobalUI18nStore(config: any): UI18nStoreInstance;
/**
* 获取全局UI18n Store
*/
export declare function getGlobalUI18nStore(): UI18nStoreInstance;
/**
* 便捷的翻译函数(使用全局store)
*/
export declare function t(text: string, options?: any): Promise<string>;