locai 2.1.1 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +37 -897
- package/dist/cli.d.ts +2 -0
- package/dist/commands/review.d.ts +109 -0
- package/dist/commands/translator.d.ts +23 -0
- package/dist/config/index.d.ts +145 -0
- package/dist/core/adapters/base-adapter.d.ts +20 -0
- package/dist/core/adapters/factory.d.ts +16 -0
- package/dist/core/adapters/json-adapter.d.ts +9 -0
- package/dist/core/adapters/po-adapter.d.ts +9 -0
- package/dist/core/adapters/properties-adapter.d.ts +9 -0
- package/dist/core/adapters/yaml-adapter.d.ts +9 -0
- package/dist/core/context-processor.d.ts +81 -0
- package/dist/core/detection/framework-detector.d.ts +9 -0
- package/dist/core/detection/structure-detector.d.ts +9 -0
- package/dist/core/fallback-provider.d.ts +54 -0
- package/dist/core/orchestrator.d.ts +101 -0
- package/dist/core/orchestrator.js +0 -1
- package/dist/core/pipeline/Pipeline.d.ts +23 -0
- package/dist/core/pipeline/PipelineStep.d.ts +18 -0
- package/dist/core/pipeline/context.d.ts +29 -0
- package/dist/core/pipeline/steps/CacheReadStep.d.ts +25 -0
- package/dist/core/pipeline/steps/CacheWriteStep.d.ts +11 -0
- package/dist/core/pipeline/steps/ConfidenceCheckStep.d.ts +10 -0
- package/dist/core/pipeline/steps/GlossaryPostStep.d.ts +9 -0
- package/dist/core/pipeline/steps/GlossaryPreStep.d.ts +9 -0
- package/dist/core/pipeline/steps/InputValidationStep.d.ts +8 -0
- package/dist/core/pipeline/steps/QualityCheckStep.d.ts +10 -0
- package/dist/core/pipeline/steps/ToneCheckStep.d.ts +13 -0
- package/dist/core/pipeline/steps/TranslationStep.d.ts +22 -0
- package/dist/core/pipeline/steps/VectorCacheReadStep.d.ts +17 -0
- package/dist/core/pipeline/steps/VectorCacheWriteStep.d.ts +11 -0
- package/dist/core/pipeline/steps/__tests__/ToneCheckStep.test.d.ts +1 -0
- package/dist/core/provider-factory.d.ts +41 -0
- package/dist/providers/base-provider.d.ts +66 -0
- package/dist/providers/dashscope.d.ts +24 -0
- package/dist/providers/deepseek.d.ts +22 -0
- package/dist/providers/gemini.d.ts +22 -0
- package/dist/providers/openai.d.ts +28 -0
- package/dist/providers/xai.d.ts +22 -0
- package/dist/services/embedding-provider.d.ts +26 -0
- package/dist/services/translation-service.d.ts +138 -0
- package/dist/services/translation-service.js +1 -1
- package/dist/services/vector-store.d.ts +26 -0
- package/dist/utils/ai-context-analyzer.d.ts +73 -0
- package/dist/utils/confidence-scorer.d.ts +77 -0
- package/dist/utils/error-helper.d.ts +87 -0
- package/dist/utils/file-manager.d.ts +129 -0
- package/dist/utils/glossary-manager.d.ts +69 -0
- package/dist/utils/graceful-shutdown.d.ts +22 -0
- package/dist/utils/input-validator.d.ts +227 -0
- package/dist/utils/logger.d.ts +134 -0
- package/dist/utils/object-transformer.d.ts +38 -0
- package/dist/utils/progress-tracker.d.ts +63 -0
- package/dist/utils/prompt-templates.d.ts +37 -0
- package/dist/utils/quality/__tests__/tone-verifier.test.d.ts +1 -0
- package/dist/utils/quality/base-checker.d.ts +79 -0
- package/dist/utils/quality/code-block-checker.d.ts +64 -0
- package/dist/utils/quality/html-tag-checker.d.ts +33 -0
- package/dist/utils/quality/index.d.ts +39 -0
- package/dist/utils/quality/length-checker.d.ts +70 -0
- package/dist/utils/quality/markdown-checker.d.ts +63 -0
- package/dist/utils/quality/placeholder-checker.d.ts +42 -0
- package/dist/utils/quality/punctuation-checker.d.ts +31 -0
- package/dist/utils/quality/quote-balance-checker.d.ts +37 -0
- package/dist/utils/quality/special-characters-checker.d.ts +66 -0
- package/dist/utils/quality/style-guide-checker.d.ts +71 -0
- package/dist/utils/quality/text-sanitizer.d.ts +51 -0
- package/dist/utils/quality/tone-verifier.d.ts +14 -0
- package/dist/utils/rate-limiter.d.ts +73 -0
- package/dist/utils/retry-helper.d.ts +49 -0
- package/dist/utils/state-manager.d.ts +62 -0
- package/dist/utils/statistics-manager.d.ts +47 -0
- package/dist/utils/ui-manager.d.ts +21 -0
- package/package.json +19 -4
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advanced Logging System.
|
|
3
|
+
* Implements saveErrorLogs, logDirectory, logRotation, and other logging features.
|
|
4
|
+
*/
|
|
5
|
+
export interface LogRotationConfig {
|
|
6
|
+
enabled: boolean;
|
|
7
|
+
maxFiles: number;
|
|
8
|
+
maxSize: number;
|
|
9
|
+
}
|
|
10
|
+
export interface LoggerConfig {
|
|
11
|
+
verbose?: boolean;
|
|
12
|
+
diagnosticsLevel?: "minimal" | "normal" | "detailed";
|
|
13
|
+
outputFormat?: "pretty" | "json" | "simple";
|
|
14
|
+
saveErrorLogs?: boolean;
|
|
15
|
+
logDirectory?: string;
|
|
16
|
+
includeTimestamps?: boolean;
|
|
17
|
+
logRotation?: Partial<LogRotationConfig>;
|
|
18
|
+
}
|
|
19
|
+
interface InternalLoggerConfig extends Required<Omit<LoggerConfig, "logRotation">> {
|
|
20
|
+
logRotation: LogRotationConfig;
|
|
21
|
+
}
|
|
22
|
+
interface LogStats {
|
|
23
|
+
size: number;
|
|
24
|
+
sizeFormatted: string;
|
|
25
|
+
modified: Date | null;
|
|
26
|
+
}
|
|
27
|
+
declare class Logger {
|
|
28
|
+
config: InternalLoggerConfig;
|
|
29
|
+
logFiles: Record<string, string>;
|
|
30
|
+
currentLogSizes: Record<string, number>;
|
|
31
|
+
private initialized;
|
|
32
|
+
/**
|
|
33
|
+
* Create a new Logger instance.
|
|
34
|
+
* @param config - Logger configuration.
|
|
35
|
+
*/
|
|
36
|
+
constructor(config?: LoggerConfig);
|
|
37
|
+
/**
|
|
38
|
+
* Initialize logger (create directories, check rotation).
|
|
39
|
+
*/
|
|
40
|
+
initialize(): Promise<void>;
|
|
41
|
+
/**
|
|
42
|
+
* Parse size string (e.g., "10MB") to bytes.
|
|
43
|
+
* @param sizeStr - Size string to parse.
|
|
44
|
+
*/
|
|
45
|
+
parseSize(sizeStr: any): number;
|
|
46
|
+
/**
|
|
47
|
+
* Check and rotate logs if needed.
|
|
48
|
+
*/
|
|
49
|
+
checkAndRotateLogs(): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Rotate a log file.
|
|
52
|
+
* @param logPath - Path to the log file.
|
|
53
|
+
*/
|
|
54
|
+
rotateLog(logPath: string): Promise<void>;
|
|
55
|
+
/**
|
|
56
|
+
* Clean up old log files.
|
|
57
|
+
* @param dir - Directory containing log files.
|
|
58
|
+
* @param basename - Basename of the log file.
|
|
59
|
+
*/
|
|
60
|
+
cleanupOldLogs(dir: string, basename: string): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Format log message.
|
|
63
|
+
* @param level - Log level.
|
|
64
|
+
* @param message - Log message.
|
|
65
|
+
* @param data - Additional data to log.
|
|
66
|
+
*/
|
|
67
|
+
formatMessage(level: string, message: string, data?: any): string;
|
|
68
|
+
/**
|
|
69
|
+
* Write to log file.
|
|
70
|
+
* @param level - Log level.
|
|
71
|
+
* @param message - Log message.
|
|
72
|
+
* @param data - Additional data to log.
|
|
73
|
+
*/
|
|
74
|
+
writeToFile(level: string, message: string, data?: any): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Simple console log with debug awareness.
|
|
77
|
+
* @param message - Message to log
|
|
78
|
+
* @param debugOnly - Only log if debug mode is enabled
|
|
79
|
+
*/
|
|
80
|
+
log(message: string, debugOnly?: boolean): Promise<void>;
|
|
81
|
+
/**
|
|
82
|
+
* Log error.
|
|
83
|
+
* @param message - Error message.
|
|
84
|
+
* @param data - Additional data.
|
|
85
|
+
*/
|
|
86
|
+
error(message: string, data?: any): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Log warning.
|
|
89
|
+
* @param message - Warning message.
|
|
90
|
+
* @param data - Additional data.
|
|
91
|
+
*/
|
|
92
|
+
warn(message: string, data?: any): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Log info.
|
|
95
|
+
* @param message - Info message.
|
|
96
|
+
* @param data - Additional data.
|
|
97
|
+
*/
|
|
98
|
+
info(message: string, data?: any): Promise<void>;
|
|
99
|
+
/**
|
|
100
|
+
* Log debug.
|
|
101
|
+
* @param message - Debug message.
|
|
102
|
+
* @param data - Additional data.
|
|
103
|
+
*/
|
|
104
|
+
debug(message: string, data?: any): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* Log based on diagnostics level.
|
|
107
|
+
* @param level - Log level.
|
|
108
|
+
* @param message - Log message.
|
|
109
|
+
* @param data - Additional data.
|
|
110
|
+
*/
|
|
111
|
+
diagnostics(level: string, message: string, data?: any): Promise<void>;
|
|
112
|
+
/**
|
|
113
|
+
* Get log statistics.
|
|
114
|
+
* @returns Object containing log stats.
|
|
115
|
+
*/
|
|
116
|
+
getLogStats(): Promise<Record<string, LogStats>>;
|
|
117
|
+
/**
|
|
118
|
+
* Format size to human-readable.
|
|
119
|
+
* @param bytes - Size in bytes.
|
|
120
|
+
*/
|
|
121
|
+
formatSize(bytes: number): string;
|
|
122
|
+
/**
|
|
123
|
+
* Clear all logs.
|
|
124
|
+
*/
|
|
125
|
+
clearLogs(): Promise<void>;
|
|
126
|
+
}
|
|
127
|
+
export declare function getLogger(config?: LoggerConfig | null): Logger;
|
|
128
|
+
/**
|
|
129
|
+
* Quick debug-aware logging helper.
|
|
130
|
+
* @param message - Message to log.
|
|
131
|
+
* @param debugOnly - Only log in debug/verbose mode.
|
|
132
|
+
*/
|
|
133
|
+
export declare function log(message: string, debugOnly?: boolean): void;
|
|
134
|
+
export default Logger;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility class for object manipulation.
|
|
3
|
+
*/
|
|
4
|
+
export interface TransformedObject {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}
|
|
7
|
+
declare class ObjectTransformer {
|
|
8
|
+
/**
|
|
9
|
+
* Flatten a nested object into a single-level object with dot notation keys.
|
|
10
|
+
* @param obj - The object to flatten.
|
|
11
|
+
* @param prefix - Prefix for keys (used internally).
|
|
12
|
+
* @param maxDepth - Maximum recursion depth.
|
|
13
|
+
* @returns Flattened object.
|
|
14
|
+
*/
|
|
15
|
+
static flatten(obj: TransformedObject, prefix?: string, maxDepth?: number): Record<string, string | number | boolean | null>;
|
|
16
|
+
/**
|
|
17
|
+
* Unflatten an object with dot notation keys into a nested object.
|
|
18
|
+
* @param obj - The flattened object.
|
|
19
|
+
* @returns Nested object.
|
|
20
|
+
*/
|
|
21
|
+
static unflatten(obj: Record<string, any>): TransformedObject;
|
|
22
|
+
/**
|
|
23
|
+
* Create a deep copy of an object.
|
|
24
|
+
* @param obj - The object to clone.
|
|
25
|
+
* @param seen - Internal set to track circular references.
|
|
26
|
+
* @returns Deep copy of the object.
|
|
27
|
+
*/
|
|
28
|
+
static deepClone<T>(obj: T, seen?: WeakSet<object>): T;
|
|
29
|
+
/**
|
|
30
|
+
* deeply merge two objects.
|
|
31
|
+
* @param target - The target object.
|
|
32
|
+
* @param source - The source object.
|
|
33
|
+
* @param overwriteArrays - Whether to overwrite arrays or merge them.
|
|
34
|
+
* @returns Merged object.
|
|
35
|
+
*/
|
|
36
|
+
static mergeObjects(target: TransformedObject, source: TransformedObject, overwriteArrays?: boolean): TransformedObject;
|
|
37
|
+
}
|
|
38
|
+
export default ObjectTransformer;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Progress tracking for translation operations
|
|
3
|
+
*/
|
|
4
|
+
export interface ProgressOptions {
|
|
5
|
+
logToConsole?: boolean;
|
|
6
|
+
logFrequency?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ProgressStatistics {
|
|
9
|
+
avgTimePerItem: number;
|
|
10
|
+
recentAvgTimePerItem?: number;
|
|
11
|
+
totalTime: number;
|
|
12
|
+
estimatedTimeRemaining: number;
|
|
13
|
+
itemsPerSecond: number;
|
|
14
|
+
percentComplete: number;
|
|
15
|
+
successRate: number;
|
|
16
|
+
startTime?: string;
|
|
17
|
+
estimatedEndTime?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface ProgressStatus {
|
|
20
|
+
total: number;
|
|
21
|
+
completed: number;
|
|
22
|
+
success: number;
|
|
23
|
+
failed: number;
|
|
24
|
+
language: string | null;
|
|
25
|
+
inProgress: boolean;
|
|
26
|
+
statistics: ProgressStatistics;
|
|
27
|
+
}
|
|
28
|
+
declare class ProgressTracker {
|
|
29
|
+
private logToConsole;
|
|
30
|
+
private logFrequency;
|
|
31
|
+
private _isUpdating;
|
|
32
|
+
private _pendingUpdates;
|
|
33
|
+
private _spinnerInterval;
|
|
34
|
+
private _spinnerIndex;
|
|
35
|
+
private _spinnerFrames;
|
|
36
|
+
private total;
|
|
37
|
+
private completed;
|
|
38
|
+
private success;
|
|
39
|
+
private failed;
|
|
40
|
+
private startTime;
|
|
41
|
+
private endTime;
|
|
42
|
+
private lastUpdateTime;
|
|
43
|
+
private recentOperationTimes;
|
|
44
|
+
private language;
|
|
45
|
+
private isCompleted;
|
|
46
|
+
private statistics;
|
|
47
|
+
constructor(options?: ProgressOptions);
|
|
48
|
+
reset(): void;
|
|
49
|
+
start(total: number, language?: string | null): void;
|
|
50
|
+
increment(type?: string): void;
|
|
51
|
+
private _processUpdate;
|
|
52
|
+
private _ensureDataConsistency;
|
|
53
|
+
private _processPendingUpdates;
|
|
54
|
+
private _shouldLog;
|
|
55
|
+
private _startSpinner;
|
|
56
|
+
private _stopSpinner;
|
|
57
|
+
private _renderProgress;
|
|
58
|
+
private _updateStatistics;
|
|
59
|
+
private _finalReport;
|
|
60
|
+
getStatus(): ProgressStatus;
|
|
61
|
+
setLogToConsole(value: boolean): void;
|
|
62
|
+
}
|
|
63
|
+
export default ProgressTracker;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prompt template utilities for translation and analysis
|
|
3
|
+
*/
|
|
4
|
+
export interface PromptOptions {
|
|
5
|
+
mode?: "smart" | "strict" | "flexible" | "exact" | "relaxed";
|
|
6
|
+
lengthControl?: any;
|
|
7
|
+
targetLang?: string;
|
|
8
|
+
detectedContext?: {
|
|
9
|
+
category?: string;
|
|
10
|
+
confidence?: number;
|
|
11
|
+
prompt?: string;
|
|
12
|
+
existingTranslation?: string;
|
|
13
|
+
similarTranslation?: {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
similarity: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
styleGuide?: {
|
|
20
|
+
formality?: string;
|
|
21
|
+
toneOfVoice?: string;
|
|
22
|
+
};
|
|
23
|
+
categories?: Record<string, any>;
|
|
24
|
+
allowNewCategories?: boolean;
|
|
25
|
+
model?: string;
|
|
26
|
+
temperature?: number;
|
|
27
|
+
maxTokens?: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Get translation prompt
|
|
31
|
+
*/
|
|
32
|
+
declare const getPrompt: (provider: string, sourceLang: string, targetLang: string, text: string, options?: PromptOptions) => any;
|
|
33
|
+
/**
|
|
34
|
+
* Get analysis prompt
|
|
35
|
+
*/
|
|
36
|
+
declare const getAnalysisPrompt: (provider: string, text: string, options?: PromptOptions) => any;
|
|
37
|
+
export { getPrompt, getAnalysisPrompt };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base Quality Checker.
|
|
3
|
+
* Common infrastructure for all quality checkers.
|
|
4
|
+
*/
|
|
5
|
+
export interface CheckerOptions {
|
|
6
|
+
placeholderConsistency?: boolean;
|
|
7
|
+
htmlTagsConsistency?: boolean;
|
|
8
|
+
punctuationCheck?: boolean;
|
|
9
|
+
lengthValidation?: boolean;
|
|
10
|
+
sanitizeOutput?: boolean;
|
|
11
|
+
rules?: Record<string, any>;
|
|
12
|
+
styleGuide?: {
|
|
13
|
+
formality?: string;
|
|
14
|
+
toneOfVoice?: string;
|
|
15
|
+
};
|
|
16
|
+
context?: Record<string, any>;
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}
|
|
19
|
+
export interface Issue {
|
|
20
|
+
type: string;
|
|
21
|
+
message: string;
|
|
22
|
+
timestamp: string;
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}
|
|
25
|
+
export interface Fix {
|
|
26
|
+
type: string;
|
|
27
|
+
message: string;
|
|
28
|
+
timestamp: string;
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}
|
|
31
|
+
export interface ValidationResult {
|
|
32
|
+
isValid: boolean;
|
|
33
|
+
issues: Issue[];
|
|
34
|
+
source?: string;
|
|
35
|
+
translated?: string;
|
|
36
|
+
context?: Record<string, any>;
|
|
37
|
+
}
|
|
38
|
+
export interface FixResult {
|
|
39
|
+
originalText: string;
|
|
40
|
+
fixedText: string;
|
|
41
|
+
isModified: boolean;
|
|
42
|
+
issues: Issue[];
|
|
43
|
+
fixes: Fix[];
|
|
44
|
+
metadata?: {
|
|
45
|
+
sourceLength: number;
|
|
46
|
+
originalLength: number;
|
|
47
|
+
fixedLength: number;
|
|
48
|
+
timestamp: string;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
declare class BaseChecker {
|
|
52
|
+
protected rules: Record<string, boolean | any>;
|
|
53
|
+
protected styleGuide: {
|
|
54
|
+
formality: string;
|
|
55
|
+
toneOfVoice: string;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Create a new BaseChecker.
|
|
59
|
+
* @param {CheckerOptions} [options={}] - Configuration options.
|
|
60
|
+
*/
|
|
61
|
+
constructor(options?: CheckerOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Create an issue object.
|
|
64
|
+
*/
|
|
65
|
+
createIssue(type: string, message: string, details?: Record<string, any>): Issue;
|
|
66
|
+
/**
|
|
67
|
+
* Create a fix object.
|
|
68
|
+
*/
|
|
69
|
+
createFix(type: string, message: string, details?: Record<string, any>): Fix;
|
|
70
|
+
/**
|
|
71
|
+
* Validate translation.
|
|
72
|
+
*/
|
|
73
|
+
validate(_sourceText: string, _translatedText: string, _options?: any): ValidationResult;
|
|
74
|
+
/**
|
|
75
|
+
* Validate and fix translation.
|
|
76
|
+
*/
|
|
77
|
+
validateAndFix(sourceText: string, translatedText: string): FixResult;
|
|
78
|
+
}
|
|
79
|
+
export default BaseChecker;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
export interface CodeBlockIssue {
|
|
2
|
+
type: "code-block-count" | "code-block-modified" | "code-block-restore";
|
|
3
|
+
severity: "error" | "critical";
|
|
4
|
+
message: string;
|
|
5
|
+
details?: any;
|
|
6
|
+
}
|
|
7
|
+
export interface CodeBlockFixResult {
|
|
8
|
+
text: string;
|
|
9
|
+
foundIssues: CodeBlockIssue[];
|
|
10
|
+
appliedFixes: {
|
|
11
|
+
type: "code-block-restore";
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
export interface CodeBlock {
|
|
16
|
+
type: "fenced" | "inline" | "html-code" | "html-pre";
|
|
17
|
+
full: string;
|
|
18
|
+
code: string;
|
|
19
|
+
position: number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Code Block Preservation Checker.
|
|
23
|
+
* Ensures code blocks are preserved exactly during translation.
|
|
24
|
+
*/
|
|
25
|
+
declare class CodeBlockChecker {
|
|
26
|
+
private codePatterns;
|
|
27
|
+
constructor();
|
|
28
|
+
/**
|
|
29
|
+
* Check if code blocks are preserved.
|
|
30
|
+
*/
|
|
31
|
+
checkCodeBlockPreservation(sourceText: string, translatedText: string): CodeBlockIssue[];
|
|
32
|
+
/**
|
|
33
|
+
* Extract all code blocks from text.
|
|
34
|
+
*/
|
|
35
|
+
extractCodeBlocks(text: string): CodeBlock[];
|
|
36
|
+
/**
|
|
37
|
+
* Fix code block preservation issues.
|
|
38
|
+
*/
|
|
39
|
+
fixCodeBlockPreservation(sourceText: string, translatedText: string): CodeBlockFixResult;
|
|
40
|
+
/**
|
|
41
|
+
* Restore missing code blocks from source.
|
|
42
|
+
*/
|
|
43
|
+
restoreCodeBlocks(sourceText: string, translatedText: string, sourceCodeBlocks: CodeBlock[]): {
|
|
44
|
+
text: string;
|
|
45
|
+
appliedFixes: any[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Protect code blocks before translation.
|
|
49
|
+
* Replaces code blocks with tokens to prevent translation.
|
|
50
|
+
*/
|
|
51
|
+
protectCodeBlocks(text: string): {
|
|
52
|
+
protectedText: string;
|
|
53
|
+
tokenMap: Map<string, string>;
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Restore code blocks after translation.
|
|
57
|
+
*/
|
|
58
|
+
restoreCodeBlocksFromTokens(text: string, tokenMap: Map<string, string>): string;
|
|
59
|
+
/**
|
|
60
|
+
* Check if text contains code blocks.
|
|
61
|
+
*/
|
|
62
|
+
hasCodeBlocks(text: string): boolean;
|
|
63
|
+
}
|
|
64
|
+
export default CodeBlockChecker;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface HtmlTagIssue {
|
|
2
|
+
type: "htmlTag";
|
|
3
|
+
message: string;
|
|
4
|
+
source?: string[];
|
|
5
|
+
translated?: string[];
|
|
6
|
+
}
|
|
7
|
+
export interface HtmlTagFixResult {
|
|
8
|
+
text: string;
|
|
9
|
+
foundIssues: HtmlTagIssue[];
|
|
10
|
+
appliedFixes: {
|
|
11
|
+
type: "htmlTag";
|
|
12
|
+
message: string;
|
|
13
|
+
}[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* HTML Tag Consistency Checker.
|
|
17
|
+
* Ensures HTML tags are preserved and correctly nested in translations.
|
|
18
|
+
*/
|
|
19
|
+
declare class HtmlTagChecker {
|
|
20
|
+
/**
|
|
21
|
+
* Check for HTML tag mismatches between source and translation.
|
|
22
|
+
*/
|
|
23
|
+
checkHtmlTags(source: string, translated: string): HtmlTagIssue[];
|
|
24
|
+
/**
|
|
25
|
+
* Fix missing HTML tags in translated text.
|
|
26
|
+
*/
|
|
27
|
+
fixHtmlTags(source: string, translated: string): HtmlTagFixResult;
|
|
28
|
+
/**
|
|
29
|
+
* Insert HTML tag into text.
|
|
30
|
+
*/
|
|
31
|
+
insertHtmlTag(text: string, tag: string): string;
|
|
32
|
+
}
|
|
33
|
+
export default HtmlTagChecker;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import BaseChecker, { CheckerOptions, FixResult, ValidationResult } from "./base-checker.js";
|
|
2
|
+
/**
|
|
3
|
+
* Main Quality Checker Class.
|
|
4
|
+
* Orchestrates various quality checks and fixes for translated text.
|
|
5
|
+
*/
|
|
6
|
+
declare class QualityChecker extends BaseChecker {
|
|
7
|
+
private placeholderChecker;
|
|
8
|
+
private htmlTagChecker;
|
|
9
|
+
private punctuationChecker;
|
|
10
|
+
private lengthChecker;
|
|
11
|
+
private textSanitizer;
|
|
12
|
+
private quoteBalanceChecker;
|
|
13
|
+
private styleGuideChecker;
|
|
14
|
+
private markdownChecker;
|
|
15
|
+
private codeBlockChecker;
|
|
16
|
+
private specialCharactersChecker;
|
|
17
|
+
private context;
|
|
18
|
+
/**
|
|
19
|
+
* Initialize QualityChecker with options.
|
|
20
|
+
*/
|
|
21
|
+
constructor(options?: CheckerOptions);
|
|
22
|
+
/**
|
|
23
|
+
* Initialize all individual checkers.
|
|
24
|
+
*/
|
|
25
|
+
initializeCheckers(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Validate translated text against source text.
|
|
28
|
+
*/
|
|
29
|
+
validate(sourceText: string, translatedText: string, options?: Record<string, any>): ValidationResult;
|
|
30
|
+
/**
|
|
31
|
+
* Validate and attempt to fix translated text.
|
|
32
|
+
*/
|
|
33
|
+
validateAndFix(sourceText: string, translatedText: string): FixResult;
|
|
34
|
+
/**
|
|
35
|
+
* Sanitize translated text using multiple passes.
|
|
36
|
+
*/
|
|
37
|
+
sanitizeTranslation(text: string): string;
|
|
38
|
+
}
|
|
39
|
+
export default QualityChecker;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
export interface LengthConfig {
|
|
2
|
+
mode: "strict" | "flexible" | "exact" | "relaxed" | "smart";
|
|
3
|
+
maxDeviation: number;
|
|
4
|
+
minDeviation: number;
|
|
5
|
+
targetLang?: string;
|
|
6
|
+
context?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface LengthIssue {
|
|
9
|
+
type: "length";
|
|
10
|
+
severity: "critical" | "warning" | "error";
|
|
11
|
+
message: string;
|
|
12
|
+
details: {
|
|
13
|
+
mode?: string;
|
|
14
|
+
context?: string;
|
|
15
|
+
targetLang?: string;
|
|
16
|
+
sourceLength?: number;
|
|
17
|
+
translatedLength?: number;
|
|
18
|
+
ratio?: number;
|
|
19
|
+
allowedRange?: {
|
|
20
|
+
min: number;
|
|
21
|
+
max: number;
|
|
22
|
+
};
|
|
23
|
+
deviation?: number;
|
|
24
|
+
error?: string;
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Length Validation Checker.
|
|
29
|
+
* Checks if translated text length is within acceptable bounds relative to source text.
|
|
30
|
+
*/
|
|
31
|
+
declare class LengthChecker {
|
|
32
|
+
private defaultConfig;
|
|
33
|
+
constructor();
|
|
34
|
+
/**
|
|
35
|
+
* Check if translated text length is acceptable.
|
|
36
|
+
*/
|
|
37
|
+
checkLength(source: string, translated: string, options?: any): LengthIssue[];
|
|
38
|
+
/**
|
|
39
|
+
* Calculate length of text ignoring whitespace.
|
|
40
|
+
*/
|
|
41
|
+
calculateLength(text: string): number;
|
|
42
|
+
/**
|
|
43
|
+
* Get configuration for length check.
|
|
44
|
+
*/
|
|
45
|
+
getConfig(options: any): LengthConfig;
|
|
46
|
+
/**
|
|
47
|
+
* Get configuration for smart mode.
|
|
48
|
+
*/
|
|
49
|
+
getSmartModeConfig(lengthControl: any, targetLang: string, context: string): LengthConfig;
|
|
50
|
+
/**
|
|
51
|
+
* Get configuration for standard mode.
|
|
52
|
+
*/
|
|
53
|
+
getStandardModeConfig(lengthControl: any, mode: any, targetLang: string, context: string): LengthConfig;
|
|
54
|
+
/**
|
|
55
|
+
* Calculate allowed length ratio range.
|
|
56
|
+
*/
|
|
57
|
+
calculateAllowedRange(config: LengthConfig): {
|
|
58
|
+
minRatio: number;
|
|
59
|
+
maxRatio: number;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Determine severity of length mismatch.
|
|
63
|
+
*/
|
|
64
|
+
determineSeverity(ratio: number, minRatio: number, maxRatio: number): "critical" | "warning";
|
|
65
|
+
/**
|
|
66
|
+
* Generate error message for length mismatch.
|
|
67
|
+
*/
|
|
68
|
+
generateErrorMessage(ratio: number, config: LengthConfig): string;
|
|
69
|
+
}
|
|
70
|
+
export default LengthChecker;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export interface MarkdownIssue {
|
|
2
|
+
type: "markdown-preservation" | "markdown-link" | "markdown-missing";
|
|
3
|
+
severity: "error" | "warning" | "critical";
|
|
4
|
+
message: string;
|
|
5
|
+
pattern?: string;
|
|
6
|
+
details?: any;
|
|
7
|
+
}
|
|
8
|
+
export interface MarkdownFixResult {
|
|
9
|
+
text: string;
|
|
10
|
+
foundIssues: MarkdownIssue[];
|
|
11
|
+
appliedFixes: {
|
|
12
|
+
type: "markdown-link";
|
|
13
|
+
message: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Markdown Preservation Checker.
|
|
18
|
+
* Ensures markdown formatting is preserved during translation.
|
|
19
|
+
*/
|
|
20
|
+
declare class MarkdownChecker {
|
|
21
|
+
private markdownPatterns;
|
|
22
|
+
constructor();
|
|
23
|
+
/**
|
|
24
|
+
* Check if markdown is preserved between source and translation.
|
|
25
|
+
*/
|
|
26
|
+
checkMarkdownPreservation(sourceText: string, translatedText: string): MarkdownIssue[];
|
|
27
|
+
/**
|
|
28
|
+
* Check for broken markdown links.
|
|
29
|
+
*/
|
|
30
|
+
checkBrokenMarkdownLinks(text: string): MarkdownIssue[];
|
|
31
|
+
/**
|
|
32
|
+
* Fix markdown preservation issues.
|
|
33
|
+
*/
|
|
34
|
+
fixMarkdownPreservation(sourceText: string, translatedText: string): MarkdownFixResult;
|
|
35
|
+
/**
|
|
36
|
+
* Extract markdown elements from text.
|
|
37
|
+
*/
|
|
38
|
+
extractMarkdownElements(text: string): Record<string, any[]>;
|
|
39
|
+
/**
|
|
40
|
+
* Restore markdown elements that were lost in translation.
|
|
41
|
+
*/
|
|
42
|
+
restoreMarkdownElements(text: string, elements: any[], type: string): {
|
|
43
|
+
text: string;
|
|
44
|
+
foundIssues: MarkdownIssue[];
|
|
45
|
+
appliedFixes: any[];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Fix broken markdown links.
|
|
49
|
+
*/
|
|
50
|
+
fixBrokenLinks(text: string): {
|
|
51
|
+
text: string;
|
|
52
|
+
foundIssues: MarkdownIssue[];
|
|
53
|
+
appliedFixes: {
|
|
54
|
+
type: "markdown-link";
|
|
55
|
+
message: string;
|
|
56
|
+
}[];
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Check if text contains markdown.
|
|
60
|
+
*/
|
|
61
|
+
hasMarkdown(text: string): boolean;
|
|
62
|
+
}
|
|
63
|
+
export default MarkdownChecker;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export interface PlaceholderIssue {
|
|
2
|
+
type: "placeholder";
|
|
3
|
+
message: string;
|
|
4
|
+
source?: string[] | string;
|
|
5
|
+
translated?: string[] | string;
|
|
6
|
+
corrupted?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PlaceholderFixResult {
|
|
9
|
+
text: string;
|
|
10
|
+
foundIssues: PlaceholderIssue[];
|
|
11
|
+
appliedFixes: {
|
|
12
|
+
type: "placeholder";
|
|
13
|
+
message: string;
|
|
14
|
+
}[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Placeholder Consistency Checker.
|
|
18
|
+
* Ensures placeholders like {name}, ${value}, %s are preserved correctly.
|
|
19
|
+
*/
|
|
20
|
+
declare class PlaceholderChecker {
|
|
21
|
+
/**
|
|
22
|
+
* Check for placeholder mismatches or corruptions.
|
|
23
|
+
*/
|
|
24
|
+
checkPlaceholders(source: string, translated: string): PlaceholderIssue[];
|
|
25
|
+
/**
|
|
26
|
+
* Fix corrupted or missing placeholders in translated text.
|
|
27
|
+
*/
|
|
28
|
+
fixPlaceholders(source: string, translated: string): PlaceholderFixResult;
|
|
29
|
+
/**
|
|
30
|
+
* Find a corrupted version of a placeholder in translated text.
|
|
31
|
+
*/
|
|
32
|
+
findCorruptedPlaceholder(translated: string, sourcePlaceholder: string): string | null;
|
|
33
|
+
/**
|
|
34
|
+
* Find best position to insert a missing placeholder.
|
|
35
|
+
*/
|
|
36
|
+
findBestPlaceholderPosition(translated: string, source: string, placeholder: string): number;
|
|
37
|
+
/**
|
|
38
|
+
* Insert placeholder into text at specified position.
|
|
39
|
+
*/
|
|
40
|
+
insertPlaceholder(text: string, placeholder: string, position: number): string;
|
|
41
|
+
}
|
|
42
|
+
export default PlaceholderChecker;
|