auto-translate-json-library 1.5.5 → 2.0.2
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/README.MD +1141 -148
- package/build/package.json +96 -22
- package/build/src/aws.d.ts +1 -1
- package/build/src/aws.js +27 -38
- package/build/src/azure.d.ts +1 -1
- package/build/src/azure.js +50 -64
- package/build/src/bin/cli.d.ts +1 -1
- package/build/src/bin/cli.js +196 -37
- package/build/src/config.d.ts +1 -0
- package/build/src/config.js +1 -2
- package/build/src/deepl.d.ts +1 -1
- package/build/src/deepl.js +18 -64
- package/build/src/files.d.ts +11 -2
- package/build/src/files.js +356 -69
- package/build/src/folderFiles.d.ts +6 -3
- package/build/src/folderFiles.js +33 -44
- package/build/src/format/arb-handler.d.ts +33 -0
- package/build/src/format/arb-handler.js +679 -0
- package/build/src/format/base-format-handler.d.ts +75 -0
- package/build/src/format/base-format-handler.js +166 -0
- package/build/src/format/csv-handler.d.ts +38 -0
- package/build/src/format/csv-handler.js +604 -0
- package/build/src/format/index.d.ts +17 -0
- package/build/src/format/index.js +48 -0
- package/build/src/format/json-handler.d.ts +17 -0
- package/build/src/format/json-handler.js +294 -0
- package/build/src/format/po-handler.d.ts +17 -0
- package/build/src/format/po-handler.js +338 -0
- package/build/src/format/po-utils.d.ts +86 -0
- package/build/src/format/po-utils.js +385 -0
- package/build/src/format/pot-handler.d.ts +22 -0
- package/build/src/format/pot-handler.js +331 -0
- package/build/src/format/properties-handler.d.ts +26 -0
- package/build/src/format/properties-handler.js +500 -0
- package/build/src/format/tsv-handler.d.ts +13 -0
- package/build/src/format/tsv-handler.js +67 -0
- package/build/src/format/xliff-handler.d.ts +24 -0
- package/build/src/format/xliff-handler.js +433 -0
- package/build/src/format/xmb-handler.d.ts +33 -0
- package/build/src/format/xmb-handler.js +484 -0
- package/build/src/format/xmb-xtb-utils.d.ts +43 -0
- package/build/src/format/xmb-xtb-utils.js +180 -0
- package/build/src/format/xml-handler.d.ts +28 -0
- package/build/src/format/xml-handler.js +561 -0
- package/build/src/format/xtb-handler.d.ts +33 -0
- package/build/src/format/xtb-handler.js +518 -0
- package/build/src/format/yaml-handler.d.ts +26 -0
- package/build/src/format/yaml-handler.js +522 -0
- package/build/src/format-detector.d.ts +7 -0
- package/build/src/format-detector.js +58 -0
- package/build/src/format-handler-factory.d.ts +9 -0
- package/build/src/format-handler-factory.js +18 -0
- package/build/src/format.interface.d.ts +56 -0
- package/build/src/format.interface.js +1 -0
- package/build/src/google.d.ts +1 -1
- package/build/src/google.js +32 -49
- package/build/src/index.d.ts +4 -3
- package/build/src/index.js +15 -17
- package/build/src/lib.d.ts +1 -1
- package/build/src/lib.js +188 -133
- package/build/src/openai.d.ts +2 -2
- package/build/src/openai.js +59 -50
- package/build/src/translate.interface.d.ts +1 -1
- package/build/src/translate.interface.js +1 -2
- package/build/src/util.js +4 -9
- package/build/src/validation/enhanced-validation-result.d.ts +96 -0
- package/build/src/validation/enhanced-validation-result.js +198 -0
- package/build/src/validation/error-messages.d.ts +88 -0
- package/build/src/validation/error-messages.js +436 -0
- package/build/src/validation/error-recovery.d.ts +78 -0
- package/build/src/validation/error-recovery.js +593 -0
- package/build/src/validation/example-usage.d.ts +31 -0
- package/build/src/validation/example-usage.js +148 -0
- package/build/src/validation/format-rules.d.ts +37 -0
- package/build/src/validation/format-rules.js +550 -0
- package/build/src/validation/format-validator.d.ts +70 -0
- package/build/src/validation/format-validator.js +279 -0
- package/build/src/validation/index.d.ts +13 -0
- package/build/src/validation/index.js +30 -0
- package/build/src/validation/validation-service.d.ts +56 -0
- package/build/src/validation/validation-service.js +262 -0
- package/build/tests/arb-handler.test.d.ts +1 -0
- package/build/tests/arb-handler.test.js +694 -0
- package/build/tests/cli-integration.test.d.ts +1 -0
- package/build/tests/cli-integration.test.js +352 -0
- package/build/tests/csv-handler.test.d.ts +1 -0
- package/build/tests/csv-handler.test.js +507 -0
- package/build/tests/error-handling.test.d.ts +1 -0
- package/build/tests/error-handling.test.js +456 -0
- package/build/tests/files-integration.test.d.ts +1 -0
- package/build/tests/files-integration.test.js +421 -0
- package/build/tests/json-handler.test.d.ts +1 -0
- package/build/tests/json-handler.test.js +526 -0
- package/build/tests/po-handler.test.d.ts +1 -0
- package/build/tests/po-handler.test.js +768 -0
- package/build/tests/properties-handler.test.d.ts +1 -0
- package/build/tests/properties-handler.test.js +316 -0
- package/build/tests/setup.d.ts +1 -0
- package/build/tests/setup.js +5 -0
- package/build/tests/xliff-handler.test.d.ts +1 -0
- package/build/tests/xliff-handler.test.js +459 -0
- package/build/tests/xmb-xtb-handler.test.d.ts +1 -0
- package/build/tests/xmb-xtb-handler.test.js +758 -0
- package/build/tests/xml-handler.test.d.ts +1 -0
- package/build/tests/xml-handler.test.js +570 -0
- package/build/tests/yaml-handler.test.d.ts +1 -0
- package/build/tests/yaml-handler.test.js +156 -0
- package/package.json +96 -22
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Example usage of the comprehensive validation and error handling system
|
|
3
|
+
* This file demonstrates how to use the validation system in practice
|
|
4
|
+
*/
|
|
5
|
+
import { ArbHandler } from "../format/arb-handler.js";
|
|
6
|
+
import { JsonHandler } from "../format/json-handler.js";
|
|
7
|
+
import { XliffHandler } from "../format/xliff-handler.js";
|
|
8
|
+
import { initializeValidation, ValidationService } from "./index.js";
|
|
9
|
+
// Initialize the validation system
|
|
10
|
+
initializeValidation();
|
|
11
|
+
/**
|
|
12
|
+
* Example: Validate a JSON file with error recovery
|
|
13
|
+
*/
|
|
14
|
+
export async function validateJsonExample() {
|
|
15
|
+
const jsonHandler = new JsonHandler();
|
|
16
|
+
// Example of corrupted JSON with trailing comma
|
|
17
|
+
const corruptedJson = `{
|
|
18
|
+
"hello": "world",
|
|
19
|
+
"goodbye": "universe",
|
|
20
|
+
}`;
|
|
21
|
+
const result = await ValidationService.validateFile(corruptedJson, "example.json", jsonHandler, {
|
|
22
|
+
attemptRecovery: true,
|
|
23
|
+
includeGuidance: true,
|
|
24
|
+
strictMode: false,
|
|
25
|
+
});
|
|
26
|
+
console.log("JSON Validation Result:");
|
|
27
|
+
console.log(ValidationService.createValidationReport(result));
|
|
28
|
+
return result;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Example: Validate an XLIFF file with strict mode
|
|
32
|
+
*/
|
|
33
|
+
export async function validateXliffExample() {
|
|
34
|
+
const xliffHandler = new XliffHandler();
|
|
35
|
+
// Example XLIFF with missing version
|
|
36
|
+
const xliffContent = `<?xml version="1.0" encoding="UTF-8"?>
|
|
37
|
+
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2">
|
|
38
|
+
<file original="test.properties" datatype="plaintext">
|
|
39
|
+
<body>
|
|
40
|
+
<trans-unit id="hello">
|
|
41
|
+
<source>Hello</source>
|
|
42
|
+
<target>Hola</target>
|
|
43
|
+
</trans-unit>
|
|
44
|
+
</body>
|
|
45
|
+
</file>
|
|
46
|
+
</xliff>`;
|
|
47
|
+
const result = await ValidationService.validateFile(xliffContent, "example.xlf", xliffHandler, {
|
|
48
|
+
attemptRecovery: false,
|
|
49
|
+
includeGuidance: true,
|
|
50
|
+
strictMode: true,
|
|
51
|
+
});
|
|
52
|
+
console.log("XLIFF Validation Result:");
|
|
53
|
+
console.log(ValidationService.createValidationReport(result));
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Example: Validate an ARB file with ICU syntax
|
|
58
|
+
*/
|
|
59
|
+
export async function validateArbExample() {
|
|
60
|
+
const arbHandler = new ArbHandler();
|
|
61
|
+
// Example ARB with ICU syntax error
|
|
62
|
+
const arbContent = `{
|
|
63
|
+
"@@locale": "en",
|
|
64
|
+
"welcome": "Welcome {name}!",
|
|
65
|
+
"@welcome": {
|
|
66
|
+
"description": "Welcome message",
|
|
67
|
+
"placeholders": {
|
|
68
|
+
"name": {
|
|
69
|
+
"type": "String",
|
|
70
|
+
"example": "John"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
"itemCount": "{count, plural, =0{no items} =1{one item} other{# items}",
|
|
75
|
+
"@itemCount": {
|
|
76
|
+
"description": "Item count message"
|
|
77
|
+
}
|
|
78
|
+
}`;
|
|
79
|
+
const result = await ValidationService.validateFile(arbContent, "example.arb", arbHandler, {
|
|
80
|
+
attemptRecovery: true,
|
|
81
|
+
includeGuidance: true,
|
|
82
|
+
strictMode: false,
|
|
83
|
+
});
|
|
84
|
+
console.log("ARB Validation Result:");
|
|
85
|
+
console.log(ValidationService.createValidationReport(result));
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Example: Handle completely corrupted file with fallback recovery
|
|
90
|
+
*/
|
|
91
|
+
export async function validateCorruptedFileExample() {
|
|
92
|
+
const jsonHandler = new JsonHandler();
|
|
93
|
+
// Completely corrupted content
|
|
94
|
+
const corruptedContent = `This is not JSON at all!
|
|
95
|
+
But it might contain some "translatable strings" here and there.
|
|
96
|
+
Maybe even some 'quoted text' that could be useful.
|
|
97
|
+
Error: malformed data everywhere...`;
|
|
98
|
+
const result = await ValidationService.validateFile(corruptedContent, "corrupted.json", jsonHandler, {
|
|
99
|
+
attemptRecovery: true,
|
|
100
|
+
includeGuidance: true,
|
|
101
|
+
strictMode: false,
|
|
102
|
+
});
|
|
103
|
+
console.log("Corrupted File Recovery Result:");
|
|
104
|
+
console.log(ValidationService.createValidationReport(result));
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Example: Batch validation of multiple files
|
|
109
|
+
*/
|
|
110
|
+
export async function batchValidationExample() {
|
|
111
|
+
const files = [
|
|
112
|
+
{
|
|
113
|
+
content: '{"key": "value"}',
|
|
114
|
+
path: "valid.json",
|
|
115
|
+
handler: new JsonHandler(),
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
content: '{"key": "value",}',
|
|
119
|
+
path: "trailing-comma.json",
|
|
120
|
+
handler: new JsonHandler(),
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
content: '{"@@locale": "en", "msg": "Hello"}',
|
|
124
|
+
path: "valid.arb",
|
|
125
|
+
handler: new ArbHandler(),
|
|
126
|
+
},
|
|
127
|
+
];
|
|
128
|
+
console.log("Batch Validation Results:");
|
|
129
|
+
console.log("=".repeat(80));
|
|
130
|
+
for (const file of files) {
|
|
131
|
+
const result = await ValidationService.validateFile(file.content, file.path, file.handler, { attemptRecovery: true, includeGuidance: false });
|
|
132
|
+
const status = result.success ? "✅ PASS" : "❌ FAIL";
|
|
133
|
+
const summary = result.validationResult.getSummary();
|
|
134
|
+
console.log(`${status} ${file.path}: ${summary}`);
|
|
135
|
+
if (!result.success && result.recoveryResult?.success) {
|
|
136
|
+
console.log(` 🔧 Recovered using: ${result.recoveryResult.recoveryMethod}`);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
console.log("=".repeat(80));
|
|
140
|
+
}
|
|
141
|
+
// Export all examples for testing
|
|
142
|
+
export const validationExamples = {
|
|
143
|
+
validateJsonExample,
|
|
144
|
+
validateXliffExample,
|
|
145
|
+
validateArbExample,
|
|
146
|
+
validateCorruptedFileExample,
|
|
147
|
+
batchValidationExample,
|
|
148
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { FormatValidationRule } from "./format-validator.js";
|
|
2
|
+
/**
|
|
3
|
+
* Global validation rules that apply to all formats
|
|
4
|
+
*/
|
|
5
|
+
export declare const globalValidationRules: FormatValidationRule[];
|
|
6
|
+
/**
|
|
7
|
+
* JSON format validation rules
|
|
8
|
+
*/
|
|
9
|
+
export declare const jsonValidationRules: FormatValidationRule[];
|
|
10
|
+
/**
|
|
11
|
+
* XLIFF format validation rules
|
|
12
|
+
*/
|
|
13
|
+
export declare const xliffValidationRules: FormatValidationRule[];
|
|
14
|
+
/**
|
|
15
|
+
* ARB format validation rules
|
|
16
|
+
*/
|
|
17
|
+
export declare const arbValidationRules: FormatValidationRule[];
|
|
18
|
+
/**
|
|
19
|
+
* PO format validation rules
|
|
20
|
+
*/
|
|
21
|
+
export declare const poValidationRules: FormatValidationRule[];
|
|
22
|
+
/**
|
|
23
|
+
* YAML format validation rules
|
|
24
|
+
*/
|
|
25
|
+
export declare const yamlValidationRules: FormatValidationRule[];
|
|
26
|
+
/**
|
|
27
|
+
* Properties format validation rules
|
|
28
|
+
*/
|
|
29
|
+
export declare const propertiesValidationRules: FormatValidationRule[];
|
|
30
|
+
/**
|
|
31
|
+
* CSV format validation rules
|
|
32
|
+
*/
|
|
33
|
+
export declare const csvValidationRules: FormatValidationRule[];
|
|
34
|
+
/**
|
|
35
|
+
* Export all format-specific rules
|
|
36
|
+
*/
|
|
37
|
+
export declare const formatSpecificRules: Record<string, FormatValidationRule[]>;
|