UNPKG

@ui18n/angular

Version:

🅰️ Modern Angular internationalization with standalone components, signals, and dependency injection support for Angular 15+

187 lines 4.26 kB
/** * @fileoverview UI18n 通用词组库系统 * 实现智能词组匹配、复用机制和优先级管理 * @author Claude Code * @created 2025-08-23 */ /** * 词组条目接口 */ export interface PhraseEntry { /** 唯一标识符 */ id: string; /** 源文本 */ source: string; /** 翻译映射 */ translations: Record<string, string>; /** 上下文信息 */ context?: string; /** 标签分类 */ tags?: string[]; /** 优先级 (1-10, 10最高) */ priority: number; /** 创建时间 */ createdAt: number; /** 更新时间 */ updatedAt: number; /** 使用次数 */ usageCount: number; /** 来源类型 */ source_type: 'user' | 'project' | 'global' | 'system'; } /** * 词组库配置 */ export interface PhraseLibraryConfig { /** 启用词组库 */ enabled: boolean; /** 匹配阈值 (0-1) */ matchThreshold: number; /** 启用模糊匹配 */ fuzzyMatching: boolean; /** 启用上下文感知 */ contextAware: boolean; /** 自动学习新词组 */ autoLearn: boolean; /** 最大缓存条目数 */ maxCacheSize: number; /** 数据文件路径 */ dataPath: string; } /** * 匹配结果 */ export interface MatchResult { /** 匹配的词组 */ phrase: PhraseEntry; /** 匹配分数 (0-1) */ score: number; /** 匹配类型 */ matchType: 'exact' | 'partial' | 'fuzzy' | 'context'; } /** * 词组库统计信息 */ export interface PhraseLibraryStats { /** 总词组数 */ totalPhrases: number; /** 按来源类型统计 */ bySourceType: Record<string, number>; /** 按语言统计 */ byLanguage: Record<string, number>; /** 命中率 */ hitRate: number; /** 平均匹配分数 */ avgMatchScore: number; /** 最近使用的词组 */ recentlyUsed: PhraseEntry[]; } /** * 通用词组库管理器 */ export declare class PhraseLibraryManager { private config; private phrases; private indexBySource; private indexByTags; private stats; private isLoaded; constructor(config?: Partial<PhraseLibraryConfig>); /** * 初始化词组库 */ initialize(): Promise<void>; /** * 加载词组数据 */ private loadPhrases; /** * 保存词组数据 */ private savePhrases; /** * 构建索引 */ private buildIndices; /** * 文本标准化 */ private normalizeText; /** * 搜索匹配的词组 */ searchPhrases(source: string, targetLanguage: string, context?: string): Promise<MatchResult[]>; /** * 精确匹配 */ private findExactMatches; /** * 部分匹配 */ private findPartialMatches; /** * 模糊匹配(使用编辑距离) */ private findFuzzyMatches; /** * 上下文匹配 */ private findContextMatches; /** * 计算源文本相似度 */ private calculateSourceSimilarity; /** * 编辑距离算法 */ private levenshteinDistance; /** * 添加词组 */ addPhrase(phrase: Omit<PhraseEntry, 'id' | 'createdAt' | 'updatedAt' | 'usageCount'>): Promise<string>; /** * 更新词组 */ updatePhrase(id: string, updates: Partial<PhraseEntry>): Promise<boolean>; /** * 删除词组 */ deletePhrase(id: string): Promise<boolean>; /** * 记录词组使用 */ recordUsage(id: string): Promise<void>; /** * 获取统计信息 */ getStats(): PhraseLibraryStats; /** * 更新统计信息 */ private updateStats; /** * 生成唯一ID */ private generateId; /** * 导入词组 */ importPhrases(phrases: PhraseEntry[], mergeStrategy?: 'replace' | 'merge'): Promise<void>; /** * 导出词组 */ exportPhrases(): PhraseEntry[]; /** * 清理未使用的词组 */ cleanup(options?: { maxAge?: number; minUsage?: number; keepSystemPhrases?: boolean; }): Promise<number>; } /** * 默认词组库实例 */ export declare const defaultPhraseLibrary: PhraseLibraryManager; //# sourceMappingURL=phrase-library.d.ts.map