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,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[]>;