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.
Files changed (108) hide show
  1. package/README.MD +1141 -148
  2. package/build/package.json +96 -22
  3. package/build/src/aws.d.ts +1 -1
  4. package/build/src/aws.js +27 -38
  5. package/build/src/azure.d.ts +1 -1
  6. package/build/src/azure.js +50 -64
  7. package/build/src/bin/cli.d.ts +1 -1
  8. package/build/src/bin/cli.js +196 -37
  9. package/build/src/config.d.ts +1 -0
  10. package/build/src/config.js +1 -2
  11. package/build/src/deepl.d.ts +1 -1
  12. package/build/src/deepl.js +18 -64
  13. package/build/src/files.d.ts +11 -2
  14. package/build/src/files.js +356 -69
  15. package/build/src/folderFiles.d.ts +6 -3
  16. package/build/src/folderFiles.js +33 -44
  17. package/build/src/format/arb-handler.d.ts +33 -0
  18. package/build/src/format/arb-handler.js +679 -0
  19. package/build/src/format/base-format-handler.d.ts +75 -0
  20. package/build/src/format/base-format-handler.js +166 -0
  21. package/build/src/format/csv-handler.d.ts +38 -0
  22. package/build/src/format/csv-handler.js +604 -0
  23. package/build/src/format/index.d.ts +17 -0
  24. package/build/src/format/index.js +48 -0
  25. package/build/src/format/json-handler.d.ts +17 -0
  26. package/build/src/format/json-handler.js +294 -0
  27. package/build/src/format/po-handler.d.ts +17 -0
  28. package/build/src/format/po-handler.js +338 -0
  29. package/build/src/format/po-utils.d.ts +86 -0
  30. package/build/src/format/po-utils.js +385 -0
  31. package/build/src/format/pot-handler.d.ts +22 -0
  32. package/build/src/format/pot-handler.js +331 -0
  33. package/build/src/format/properties-handler.d.ts +26 -0
  34. package/build/src/format/properties-handler.js +500 -0
  35. package/build/src/format/tsv-handler.d.ts +13 -0
  36. package/build/src/format/tsv-handler.js +67 -0
  37. package/build/src/format/xliff-handler.d.ts +24 -0
  38. package/build/src/format/xliff-handler.js +433 -0
  39. package/build/src/format/xmb-handler.d.ts +33 -0
  40. package/build/src/format/xmb-handler.js +484 -0
  41. package/build/src/format/xmb-xtb-utils.d.ts +43 -0
  42. package/build/src/format/xmb-xtb-utils.js +180 -0
  43. package/build/src/format/xml-handler.d.ts +28 -0
  44. package/build/src/format/xml-handler.js +561 -0
  45. package/build/src/format/xtb-handler.d.ts +33 -0
  46. package/build/src/format/xtb-handler.js +518 -0
  47. package/build/src/format/yaml-handler.d.ts +26 -0
  48. package/build/src/format/yaml-handler.js +522 -0
  49. package/build/src/format-detector.d.ts +7 -0
  50. package/build/src/format-detector.js +58 -0
  51. package/build/src/format-handler-factory.d.ts +9 -0
  52. package/build/src/format-handler-factory.js +18 -0
  53. package/build/src/format.interface.d.ts +56 -0
  54. package/build/src/format.interface.js +1 -0
  55. package/build/src/google.d.ts +1 -1
  56. package/build/src/google.js +32 -49
  57. package/build/src/index.d.ts +4 -3
  58. package/build/src/index.js +15 -17
  59. package/build/src/lib.d.ts +1 -1
  60. package/build/src/lib.js +188 -133
  61. package/build/src/openai.d.ts +2 -2
  62. package/build/src/openai.js +59 -50
  63. package/build/src/translate.interface.d.ts +1 -1
  64. package/build/src/translate.interface.js +1 -2
  65. package/build/src/util.js +4 -9
  66. package/build/src/validation/enhanced-validation-result.d.ts +96 -0
  67. package/build/src/validation/enhanced-validation-result.js +198 -0
  68. package/build/src/validation/error-messages.d.ts +88 -0
  69. package/build/src/validation/error-messages.js +436 -0
  70. package/build/src/validation/error-recovery.d.ts +78 -0
  71. package/build/src/validation/error-recovery.js +593 -0
  72. package/build/src/validation/example-usage.d.ts +31 -0
  73. package/build/src/validation/example-usage.js +148 -0
  74. package/build/src/validation/format-rules.d.ts +37 -0
  75. package/build/src/validation/format-rules.js +550 -0
  76. package/build/src/validation/format-validator.d.ts +70 -0
  77. package/build/src/validation/format-validator.js +279 -0
  78. package/build/src/validation/index.d.ts +13 -0
  79. package/build/src/validation/index.js +30 -0
  80. package/build/src/validation/validation-service.d.ts +56 -0
  81. package/build/src/validation/validation-service.js +262 -0
  82. package/build/tests/arb-handler.test.d.ts +1 -0
  83. package/build/tests/arb-handler.test.js +694 -0
  84. package/build/tests/cli-integration.test.d.ts +1 -0
  85. package/build/tests/cli-integration.test.js +352 -0
  86. package/build/tests/csv-handler.test.d.ts +1 -0
  87. package/build/tests/csv-handler.test.js +507 -0
  88. package/build/tests/error-handling.test.d.ts +1 -0
  89. package/build/tests/error-handling.test.js +456 -0
  90. package/build/tests/files-integration.test.d.ts +1 -0
  91. package/build/tests/files-integration.test.js +421 -0
  92. package/build/tests/json-handler.test.d.ts +1 -0
  93. package/build/tests/json-handler.test.js +526 -0
  94. package/build/tests/po-handler.test.d.ts +1 -0
  95. package/build/tests/po-handler.test.js +768 -0
  96. package/build/tests/properties-handler.test.d.ts +1 -0
  97. package/build/tests/properties-handler.test.js +316 -0
  98. package/build/tests/setup.d.ts +1 -0
  99. package/build/tests/setup.js +5 -0
  100. package/build/tests/xliff-handler.test.d.ts +1 -0
  101. package/build/tests/xliff-handler.test.js +459 -0
  102. package/build/tests/xmb-xtb-handler.test.d.ts +1 -0
  103. package/build/tests/xmb-xtb-handler.test.js +758 -0
  104. package/build/tests/xml-handler.test.d.ts +1 -0
  105. package/build/tests/xml-handler.test.js +570 -0
  106. package/build/tests/yaml-handler.test.d.ts +1 -0
  107. package/build/tests/yaml-handler.test.js +156 -0
  108. package/package.json +96 -22
@@ -0,0 +1,593 @@
1
+ import { FormatDetector } from "../format-detector.js";
2
+ import { FormatHandlerFactory } from "../format-handler-factory.js";
3
+ /**
4
+ * Error recovery manager that attempts to salvage data from corrupted files
5
+ */
6
+ export class ErrorRecoveryManager {
7
+ static strategies = [];
8
+ /**
9
+ * Register a recovery strategy
10
+ */
11
+ static registerStrategy(strategy) {
12
+ this.strategies.push(strategy);
13
+ }
14
+ /**
15
+ * Attempt to recover data from a corrupted file
16
+ */
17
+ static attemptRecovery(error, content, filePath) {
18
+ const applicableStrategies = this.strategies.filter((strategy) => strategy.canRecover(error, content, filePath));
19
+ // Try strategies in order of registration
20
+ for (const strategy of applicableStrategies) {
21
+ try {
22
+ const result = strategy.recover(error, content, filePath);
23
+ if (result.success) {
24
+ return result;
25
+ }
26
+ }
27
+ catch (recoveryError) {
28
+ // Recovery strategy itself failed, continue to next strategy
29
+ console.warn(`Recovery strategy "${strategy.name}" failed:`, recoveryError);
30
+ }
31
+ }
32
+ // No recovery possible
33
+ return {
34
+ success: false,
35
+ warnings: [],
36
+ errors: [`No recovery strategy could handle the error: ${error.message}`],
37
+ recoveryMethod: "none",
38
+ originalError: error.message,
39
+ };
40
+ }
41
+ /**
42
+ * Get all registered recovery strategies
43
+ */
44
+ static getStrategies() {
45
+ return [...this.strategies];
46
+ }
47
+ /**
48
+ * Clear all strategies (useful for testing)
49
+ */
50
+ static clearStrategies() {
51
+ this.strategies.length = 0;
52
+ }
53
+ }
54
+ /**
55
+ * JSON recovery strategies
56
+ */
57
+ export const jsonRecoveryStrategies = [
58
+ {
59
+ name: "JSON Trailing Comma Fix",
60
+ description: "Remove trailing commas that cause JSON parsing errors",
61
+ canRecover: (error, content) => {
62
+ return (error.message.includes("JSON") &&
63
+ (content.includes(",}") || content.includes(",]")));
64
+ },
65
+ recover: (error, content, filePath) => {
66
+ try {
67
+ // Remove trailing commas
68
+ let fixedContent = content
69
+ .replace(/,(\s*[}\]])/g, "$1") // Remove trailing commas before } or ]
70
+ .replace(/,(\s*$)/gm, ""); // Remove trailing commas at end of lines
71
+ const parsed = JSON.parse(fixedContent);
72
+ return {
73
+ success: true,
74
+ data: parsed,
75
+ warnings: ["Fixed trailing commas in JSON"],
76
+ errors: [],
77
+ recoveryMethod: "JSON Trailing Comma Fix",
78
+ originalError: error.message,
79
+ };
80
+ }
81
+ catch (recoveryError) {
82
+ return {
83
+ success: false,
84
+ warnings: [],
85
+ errors: [
86
+ `Failed to fix trailing commas: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
87
+ ],
88
+ recoveryMethod: "JSON Trailing Comma Fix",
89
+ originalError: error.message,
90
+ };
91
+ }
92
+ },
93
+ },
94
+ {
95
+ name: "JSON Comment Removal",
96
+ description: "Remove comments from JSON files (non-standard but common)",
97
+ canRecover: (error, content) => {
98
+ return (error.message.includes("JSON") &&
99
+ (content.includes("//") || content.includes("/*")));
100
+ },
101
+ recover: (error, content, filePath) => {
102
+ try {
103
+ // Remove single-line comments
104
+ let fixedContent = content.replace(/\/\/.*$/gm, "");
105
+ // Remove multi-line comments
106
+ fixedContent = fixedContent.replace(/\/\*[\s\S]*?\*\//g, "");
107
+ const parsed = JSON.parse(fixedContent);
108
+ return {
109
+ success: true,
110
+ data: parsed,
111
+ warnings: [
112
+ "Removed comments from JSON (comments are not standard JSON)",
113
+ ],
114
+ errors: [],
115
+ recoveryMethod: "JSON Comment Removal",
116
+ originalError: error.message,
117
+ };
118
+ }
119
+ catch (recoveryError) {
120
+ return {
121
+ success: false,
122
+ warnings: [],
123
+ errors: [
124
+ `Failed to remove comments: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
125
+ ],
126
+ recoveryMethod: "JSON Comment Removal",
127
+ originalError: error.message,
128
+ };
129
+ }
130
+ },
131
+ },
132
+ {
133
+ name: "JSON Partial Recovery",
134
+ description: "Extract valid JSON objects from partially corrupted files",
135
+ canRecover: (error, content) => {
136
+ return error.message.includes("JSON") && content.includes("{");
137
+ },
138
+ recover: (error, content, filePath) => {
139
+ const warnings = [];
140
+ const errors = [];
141
+ let recoveredData = {};
142
+ try {
143
+ // Try to find valid JSON objects in the content
144
+ const lines = content.split("\n");
145
+ let currentObject = "";
146
+ let braceCount = 0;
147
+ let inString = false;
148
+ let escapeNext = false;
149
+ for (const line of lines) {
150
+ for (let i = 0; i < line.length; i++) {
151
+ const char = line[i];
152
+ if (escapeNext) {
153
+ escapeNext = false;
154
+ currentObject += char;
155
+ continue;
156
+ }
157
+ if (char === "\\") {
158
+ escapeNext = true;
159
+ currentObject += char;
160
+ continue;
161
+ }
162
+ if (char === '"' && !escapeNext) {
163
+ inString = !inString;
164
+ }
165
+ if (!inString) {
166
+ if (char === "{") {
167
+ braceCount++;
168
+ }
169
+ else if (char === "}") {
170
+ braceCount--;
171
+ }
172
+ }
173
+ currentObject += char;
174
+ // If we have a complete object, try to parse it
175
+ if (braceCount === 0 && currentObject.trim().startsWith("{")) {
176
+ try {
177
+ const parsed = JSON.parse(currentObject.trim());
178
+ if (typeof parsed === "object" && parsed !== null) {
179
+ recoveredData = { ...recoveredData, ...parsed };
180
+ warnings.push(`Recovered partial JSON object`);
181
+ }
182
+ }
183
+ catch {
184
+ // This chunk wasn't valid JSON, continue
185
+ }
186
+ currentObject = "";
187
+ }
188
+ }
189
+ }
190
+ if (Object.keys(recoveredData).length > 0) {
191
+ return {
192
+ success: true,
193
+ data: recoveredData,
194
+ warnings,
195
+ errors,
196
+ recoveryMethod: "JSON Partial Recovery",
197
+ originalError: error.message,
198
+ partialRecovery: true,
199
+ };
200
+ }
201
+ }
202
+ catch (recoveryError) {
203
+ errors.push(`Partial recovery failed: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`);
204
+ }
205
+ return {
206
+ success: false,
207
+ warnings,
208
+ errors: errors.length > 0
209
+ ? errors
210
+ : ["No valid JSON objects could be recovered"],
211
+ recoveryMethod: "JSON Partial Recovery",
212
+ originalError: error.message,
213
+ };
214
+ },
215
+ },
216
+ ];
217
+ /**
218
+ * XML recovery strategies
219
+ */
220
+ export const xmlRecoveryStrategies = [
221
+ {
222
+ name: "XML Encoding Fix",
223
+ description: "Fix common XML encoding issues",
224
+ canRecover: (error, content) => {
225
+ return (error.message.includes("XML") &&
226
+ error.message.toLowerCase().includes("encoding"));
227
+ },
228
+ recover: (error, content, filePath) => {
229
+ try {
230
+ // Try to fix common encoding issues
231
+ let fixedContent = content;
232
+ // Fix common encoding declaration issues
233
+ if (!fixedContent.includes("<?xml")) {
234
+ fixedContent =
235
+ '<?xml version="1.0" encoding="UTF-8"?>\n' + fixedContent;
236
+ }
237
+ // Fix malformed encoding declarations
238
+ fixedContent = fixedContent.replace(/<\?xml[^>]*encoding\s*=\s*["'][^"']*["'][^>]*\?>/i, '<?xml version="1.0" encoding="UTF-8"?>');
239
+ // Try to parse with a simple XML parser approach
240
+ // This is a basic recovery - in a real implementation, you'd use the actual XML parser
241
+ if (fixedContent.includes("<") && fixedContent.includes(">")) {
242
+ return {
243
+ success: true,
244
+ data: { _recovered_xml_content: fixedContent },
245
+ warnings: ["Fixed XML encoding declaration"],
246
+ errors: [],
247
+ recoveryMethod: "XML Encoding Fix",
248
+ originalError: error.message,
249
+ };
250
+ }
251
+ }
252
+ catch (recoveryError) {
253
+ return {
254
+ success: false,
255
+ warnings: [],
256
+ errors: [
257
+ `Failed to fix XML encoding: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
258
+ ],
259
+ recoveryMethod: "XML Encoding Fix",
260
+ originalError: error.message,
261
+ };
262
+ }
263
+ return {
264
+ success: false,
265
+ warnings: [],
266
+ errors: ["Could not fix XML encoding issues"],
267
+ recoveryMethod: "XML Encoding Fix",
268
+ originalError: error.message,
269
+ };
270
+ },
271
+ },
272
+ {
273
+ name: "XML Unclosed Tag Fix",
274
+ description: "Attempt to fix unclosed XML tags",
275
+ canRecover: (error, content) => {
276
+ return (error.message.includes("XML") &&
277
+ (error.message.includes("unclosed") ||
278
+ error.message.includes("not closed")));
279
+ },
280
+ recover: (error, content, filePath) => {
281
+ try {
282
+ const warnings = [];
283
+ let fixedContent = content;
284
+ // Simple approach: find unclosed tags and attempt to close them
285
+ const openTags = [];
286
+ const tagRegex = /<(\/?)([\w-]+)[^>]*>/g;
287
+ let match;
288
+ while ((match = tagRegex.exec(content)) !== null) {
289
+ const isClosing = match[1] === "/";
290
+ const tagName = match[2];
291
+ if (isClosing) {
292
+ const lastOpenTag = openTags.pop();
293
+ if (lastOpenTag !== tagName) {
294
+ warnings.push(`Mismatched closing tag: expected ${lastOpenTag}, found ${tagName}`);
295
+ }
296
+ }
297
+ else {
298
+ // Check if it's a self-closing tag
299
+ if (!match[0].endsWith("/>")) {
300
+ openTags.push(tagName);
301
+ }
302
+ }
303
+ }
304
+ // Close any remaining open tags
305
+ for (let i = openTags.length - 1; i >= 0; i--) {
306
+ fixedContent += `</${openTags[i]}>`;
307
+ warnings.push(`Added missing closing tag: ${openTags[i]}`);
308
+ }
309
+ return {
310
+ success: true,
311
+ data: { _recovered_xml_content: fixedContent },
312
+ warnings,
313
+ errors: [],
314
+ recoveryMethod: "XML Unclosed Tag Fix",
315
+ originalError: error.message,
316
+ partialRecovery: true,
317
+ };
318
+ }
319
+ catch (recoveryError) {
320
+ return {
321
+ success: false,
322
+ warnings: [],
323
+ errors: [
324
+ `Failed to fix unclosed XML tags: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
325
+ ],
326
+ recoveryMethod: "XML Unclosed Tag Fix",
327
+ originalError: error.message,
328
+ };
329
+ }
330
+ },
331
+ },
332
+ ];
333
+ /**
334
+ * Format fallback strategies
335
+ */
336
+ export const formatFallbackStrategies = [
337
+ {
338
+ name: "Format Auto-Detection Fallback",
339
+ description: "Try alternative format detection when primary format fails",
340
+ canRecover: (error, content, filePath) => {
341
+ return filePath !== undefined && content.length > 0;
342
+ },
343
+ recover: (error, content, filePath) => {
344
+ try {
345
+ const warnings = [];
346
+ // Try to detect format based on content rather than file extension
347
+ const detectedFormat = FormatDetector.detectFormat(filePath || "", content);
348
+ if (detectedFormat === "unknown") {
349
+ return {
350
+ success: false,
351
+ warnings: [],
352
+ errors: ["Could not detect file format from content"],
353
+ recoveryMethod: "Format Auto-Detection Fallback",
354
+ originalError: error.message,
355
+ };
356
+ }
357
+ // Try to get a handler for the detected format
358
+ const handler = FormatHandlerFactory.getHandler(detectedFormat);
359
+ if (!handler) {
360
+ return {
361
+ success: false,
362
+ warnings: [],
363
+ errors: [
364
+ `No handler available for detected format: ${detectedFormat}`,
365
+ ],
366
+ recoveryMethod: "Format Auto-Detection Fallback",
367
+ originalError: error.message,
368
+ };
369
+ }
370
+ // Try to parse with the detected format handler
371
+ try {
372
+ const data = handler.parse(content);
373
+ warnings.push(`Successfully parsed using ${detectedFormat} format instead of original format`);
374
+ return {
375
+ success: true,
376
+ data,
377
+ warnings,
378
+ errors: [],
379
+ recoveryMethod: "Format Auto-Detection Fallback",
380
+ originalError: error.message,
381
+ };
382
+ }
383
+ catch (parseError) {
384
+ return {
385
+ success: false,
386
+ warnings,
387
+ errors: [
388
+ `Failed to parse with detected format ${detectedFormat}: ${parseError instanceof Error ? parseError.message : String(parseError)}`,
389
+ ],
390
+ recoveryMethod: "Format Auto-Detection Fallback",
391
+ originalError: error.message,
392
+ };
393
+ }
394
+ }
395
+ catch (recoveryError) {
396
+ return {
397
+ success: false,
398
+ warnings: [],
399
+ errors: [
400
+ `Format fallback failed: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
401
+ ],
402
+ recoveryMethod: "Format Auto-Detection Fallback",
403
+ originalError: error.message,
404
+ };
405
+ }
406
+ },
407
+ },
408
+ {
409
+ name: "Plain Text Fallback",
410
+ description: "Extract translatable strings from any text content as last resort",
411
+ canRecover: (error, content) => {
412
+ return content.length > 0 && typeof content === "string";
413
+ },
414
+ recover: (error, content, filePath) => {
415
+ try {
416
+ const warnings = [];
417
+ const lines = content.split("\n");
418
+ const extractedStrings = {};
419
+ // Extract lines that look like they might contain translatable content
420
+ for (let i = 0; i < lines.length; i++) {
421
+ const line = lines[i].trim();
422
+ // Skip empty lines and lines that look like code/markup
423
+ if (line.length === 0 ||
424
+ line.startsWith("//") ||
425
+ line.startsWith("#") ||
426
+ line.startsWith("/*") ||
427
+ line.startsWith("<") ||
428
+ line.match(/^[\{\[\(\)\]\}]+$/)) {
429
+ continue;
430
+ }
431
+ // Look for quoted strings
432
+ const quotedStrings = line.match(/"([^"\\]|\\.)*"/g) || line.match(/'([^'\\]|\\.)*'/g);
433
+ if (quotedStrings) {
434
+ for (const quotedString of quotedStrings) {
435
+ const cleanString = quotedString.slice(1, -1); // Remove quotes
436
+ if (cleanString.length > 0) {
437
+ extractedStrings[`line_${i + 1}_string_${Object.keys(extractedStrings).length + 1}`] = cleanString;
438
+ }
439
+ }
440
+ }
441
+ else if (line.length > 3 &&
442
+ !line.match(/^[a-zA-Z_][a-zA-Z0-9_]*\s*[:=]/)) {
443
+ // Lines that don't look like variable assignments might be translatable
444
+ extractedStrings[`line_${i + 1}`] = line;
445
+ }
446
+ }
447
+ if (Object.keys(extractedStrings).length > 0) {
448
+ warnings.push(`Extracted ${Object.keys(extractedStrings).length} potential translatable strings from plain text`);
449
+ warnings.push("This is a fallback recovery - please verify the extracted content");
450
+ return {
451
+ success: true,
452
+ data: extractedStrings,
453
+ warnings,
454
+ errors: [],
455
+ recoveryMethod: "Plain Text Fallback",
456
+ originalError: error.message,
457
+ partialRecovery: true,
458
+ };
459
+ }
460
+ return {
461
+ success: false,
462
+ warnings: [],
463
+ errors: ["No translatable content could be extracted from the file"],
464
+ recoveryMethod: "Plain Text Fallback",
465
+ originalError: error.message,
466
+ };
467
+ }
468
+ catch (recoveryError) {
469
+ return {
470
+ success: false,
471
+ warnings: [],
472
+ errors: [
473
+ `Plain text fallback failed: ${recoveryError instanceof Error ? recoveryError.message : String(recoveryError)}`,
474
+ ],
475
+ recoveryMethod: "Plain Text Fallback",
476
+ originalError: error.message,
477
+ };
478
+ }
479
+ },
480
+ },
481
+ ];
482
+ /**
483
+ * Initialize all recovery strategies
484
+ */
485
+ export function initializeErrorRecovery() {
486
+ // Register JSON recovery strategies
487
+ for (const strategy of jsonRecoveryStrategies) {
488
+ ErrorRecoveryManager.registerStrategy(strategy);
489
+ }
490
+ // Register XML recovery strategies
491
+ for (const strategy of xmlRecoveryStrategies) {
492
+ ErrorRecoveryManager.registerStrategy(strategy);
493
+ }
494
+ // Register format fallback strategies
495
+ for (const strategy of formatFallbackStrategies) {
496
+ ErrorRecoveryManager.registerStrategy(strategy);
497
+ }
498
+ }
499
+ /**
500
+ * User guidance system for common format issues
501
+ */
502
+ export class UserGuidanceSystem {
503
+ static commonIssues = new Map([
504
+ [
505
+ "JSON_PARSE_ERROR",
506
+ [
507
+ "Check for trailing commas after the last item in objects or arrays",
508
+ "Ensure all strings are properly quoted with double quotes",
509
+ "Verify that all brackets and braces are properly matched",
510
+ "Remove any comments (JSON does not support comments)",
511
+ "Check for unescaped special characters in strings",
512
+ ],
513
+ ],
514
+ [
515
+ "XML_PARSE_ERROR",
516
+ [
517
+ "Ensure all XML tags are properly closed",
518
+ "Check that the XML declaration is properly formatted",
519
+ "Verify that attribute values are quoted",
520
+ "Ensure there are no unescaped special characters (&, <, >) in text content",
521
+ "Check for proper XML namespace declarations",
522
+ ],
523
+ ],
524
+ [
525
+ "XLIFF_VALIDATION_ERROR",
526
+ [
527
+ "Verify the XLIFF version is supported (1.2, 2.0, or 2.1)",
528
+ "Ensure all required elements (file, body, trans-unit/unit) are present",
529
+ "Check that source and target languages are specified",
530
+ "Verify that all trans-units have unique IDs",
531
+ ],
532
+ ],
533
+ [
534
+ "ARB_VALIDATION_ERROR",
535
+ [
536
+ "Add @@locale metadata to specify the language",
537
+ "Check ICU message format syntax for placeholders",
538
+ "Ensure resource metadata matches actual resources",
539
+ 'Verify that all ICU plural forms include "other"',
540
+ ],
541
+ ],
542
+ [
543
+ "PO_VALIDATION_ERROR",
544
+ [
545
+ "Check that the PO file header is present and complete",
546
+ "Verify that msgid and msgstr pairs are properly formatted",
547
+ "Ensure plural forms are correctly specified",
548
+ "Check for proper escaping of quotes and special characters",
549
+ ],
550
+ ],
551
+ [
552
+ "ENCODING_ERROR",
553
+ [
554
+ "Ensure the file is saved with the correct encoding (usually UTF-8)",
555
+ "Check for byte order marks (BOM) that might cause issues",
556
+ "Verify that special characters are properly encoded",
557
+ "Consider using Unicode escapes for problematic characters",
558
+ ],
559
+ ],
560
+ ]);
561
+ /**
562
+ * Get guidance for a specific error type
563
+ */
564
+ static getGuidance(errorType) {
565
+ return (this.commonIssues.get(errorType) || [
566
+ "Check the file format and syntax",
567
+ "Verify that the file is not corrupted",
568
+ "Try opening the file in a text editor to inspect its contents",
569
+ "Consider using a format-specific validator or linter",
570
+ ]);
571
+ }
572
+ /**
573
+ * Add custom guidance for an error type
574
+ */
575
+ static addGuidance(errorType, guidance) {
576
+ this.commonIssues.set(errorType, guidance);
577
+ }
578
+ /**
579
+ * Get formatted guidance message
580
+ */
581
+ static getFormattedGuidance(errorType, error) {
582
+ const guidance = this.getGuidance(errorType);
583
+ const lines = [
584
+ `💡 Suggestions for fixing ${errorType}:`,
585
+ ...guidance.map((item) => ` • ${item}`),
586
+ ];
587
+ if (error) {
588
+ lines.unshift(`❌ Error: ${error.message}`);
589
+ lines.push("");
590
+ }
591
+ return lines.join("\n");
592
+ }
593
+ }
@@ -0,0 +1,31 @@
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
+ /**
6
+ * Example: Validate a JSON file with error recovery
7
+ */
8
+ export declare function validateJsonExample(): Promise<import("./validation-service.js").ValidationServiceResult>;
9
+ /**
10
+ * Example: Validate an XLIFF file with strict mode
11
+ */
12
+ export declare function validateXliffExample(): Promise<import("./validation-service.js").ValidationServiceResult>;
13
+ /**
14
+ * Example: Validate an ARB file with ICU syntax
15
+ */
16
+ export declare function validateArbExample(): Promise<import("./validation-service.js").ValidationServiceResult>;
17
+ /**
18
+ * Example: Handle completely corrupted file with fallback recovery
19
+ */
20
+ export declare function validateCorruptedFileExample(): Promise<import("./validation-service.js").ValidationServiceResult>;
21
+ /**
22
+ * Example: Batch validation of multiple files
23
+ */
24
+ export declare function batchValidationExample(): Promise<void>;
25
+ export declare const validationExamples: {
26
+ validateJsonExample: typeof validateJsonExample;
27
+ validateXliffExample: typeof validateXliffExample;
28
+ validateArbExample: typeof validateArbExample;
29
+ validateCorruptedFileExample: typeof validateCorruptedFileExample;
30
+ batchValidationExample: typeof batchValidationExample;
31
+ };