auto-translate-json-library 1.5.4 → 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 +97 -21
- 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 -63
- 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 +97 -21
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { XmbHandler } from "./xmb-handler.js";
|
|
2
|
+
import { XtbHandler } from "./xtb-handler.js";
|
|
3
|
+
/**
|
|
4
|
+
* Utility class for XMB/XTB message bundle operations and integrity validation
|
|
5
|
+
*/
|
|
6
|
+
export class XmbXtbUtils {
|
|
7
|
+
xmbHandler;
|
|
8
|
+
xtbHandler;
|
|
9
|
+
constructor() {
|
|
10
|
+
this.xmbHandler = new XmbHandler();
|
|
11
|
+
this.xtbHandler = new XtbHandler();
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Validate that XTB translations maintain message integrity with XMB source
|
|
15
|
+
*/
|
|
16
|
+
validateBundleIntegrity(xmbContent, xtbContent) {
|
|
17
|
+
const errors = [];
|
|
18
|
+
const warnings = [];
|
|
19
|
+
try {
|
|
20
|
+
// Parse both files
|
|
21
|
+
const xmbData = this.xmbHandler.parse(xmbContent);
|
|
22
|
+
const xtbData = this.xtbHandler.parse(xtbContent);
|
|
23
|
+
// Get message metadata from XMB
|
|
24
|
+
const xmbMetadata = xmbData._metadata?.xmbMetadata?.messages || {};
|
|
25
|
+
// Validate each translation against its original message
|
|
26
|
+
for (const [messageId, translatedText] of Object.entries(xtbData)) {
|
|
27
|
+
if (messageId === "_metadata")
|
|
28
|
+
continue;
|
|
29
|
+
const originalMessage = xmbMetadata[messageId];
|
|
30
|
+
if (originalMessage) {
|
|
31
|
+
const originalText = originalMessage.originalText || "";
|
|
32
|
+
const integrity = this.xmbHandler.validateMessageIntegrity(originalText, String(translatedText));
|
|
33
|
+
errors.push(...integrity.errors);
|
|
34
|
+
warnings.push(...integrity.warnings);
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
warnings.push({
|
|
38
|
+
code: "ORPHANED_TRANSLATION",
|
|
39
|
+
message: `Translation for message ID "${messageId}" found but no corresponding XMB message`,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
// Check for missing translations
|
|
44
|
+
for (const messageId of Object.keys(xmbData)) {
|
|
45
|
+
if (messageId === "_metadata")
|
|
46
|
+
continue;
|
|
47
|
+
if (!xtbData[messageId]) {
|
|
48
|
+
warnings.push({
|
|
49
|
+
code: "MISSING_TRANSLATION",
|
|
50
|
+
message: `No translation found for message ID "${messageId}"`,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
errors.push({
|
|
57
|
+
code: "BUNDLE_PARSE_ERROR",
|
|
58
|
+
message: `Failed to parse bundle files: ${error instanceof Error ? error.message : String(error)}`,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
isValid: errors.length === 0,
|
|
63
|
+
errors,
|
|
64
|
+
warnings,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Generate XTB file from XMB source with translations
|
|
69
|
+
*/
|
|
70
|
+
generateXtbFromXmb(xmbContent, targetLanguage, translations) {
|
|
71
|
+
return this.xmbHandler.generateXtbFromXmb(xmbContent, targetLanguage, translations);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Update existing XTB file with new translations while preserving structure
|
|
75
|
+
*/
|
|
76
|
+
updateXtbFile(existingXtbContent, newTranslations) {
|
|
77
|
+
return this.xtbHandler.updateXtbTranslations(existingXtbContent, newTranslations);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Extract message descriptions and meanings from XMB for translator context
|
|
81
|
+
*/
|
|
82
|
+
extractTranslatorContext(xmbContent) {
|
|
83
|
+
const context = {};
|
|
84
|
+
try {
|
|
85
|
+
const xmbData = this.xmbHandler.parse(xmbContent);
|
|
86
|
+
const xmbMetadata = xmbData._metadata?.xmbMetadata?.messages || {};
|
|
87
|
+
for (const [messageId, metadata] of Object.entries(xmbMetadata)) {
|
|
88
|
+
const originalText = metadata.originalText || "";
|
|
89
|
+
context[messageId] = {
|
|
90
|
+
description: metadata.description,
|
|
91
|
+
meaning: metadata.meaning,
|
|
92
|
+
originalText,
|
|
93
|
+
placeholders: this.extractPlaceholderInfo(originalText),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
// Return empty context if parsing fails
|
|
99
|
+
}
|
|
100
|
+
return context;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Validate that message references are not broken in bundle structure
|
|
104
|
+
*/
|
|
105
|
+
validateMessageReferences(xmbContent, xtbContent) {
|
|
106
|
+
const errors = [];
|
|
107
|
+
const warnings = [];
|
|
108
|
+
try {
|
|
109
|
+
const xmbData = this.xmbHandler.parse(xmbContent);
|
|
110
|
+
const xtbData = this.xtbHandler.parse(xtbContent);
|
|
111
|
+
// Check that XTB language matches expected target
|
|
112
|
+
const xtbLanguage = xtbData._metadata?.xtbMetadata?.language;
|
|
113
|
+
const xmbLanguage = xmbData._metadata?.xmbMetadata?.locale;
|
|
114
|
+
if (xtbLanguage === xmbLanguage) {
|
|
115
|
+
warnings.push({
|
|
116
|
+
code: "SAME_LANGUAGE",
|
|
117
|
+
message: `XTB target language "${xtbLanguage}" is the same as XMB source language "${xmbLanguage}"`,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
// Validate message ID consistency
|
|
121
|
+
const xmbMessageIds = new Set(Object.keys(xmbData).filter((key) => key !== "_metadata"));
|
|
122
|
+
const xtbMessageIds = new Set(Object.keys(xtbData).filter((key) => key !== "_metadata"));
|
|
123
|
+
// Check for message ID mismatches
|
|
124
|
+
for (const xtbId of xtbMessageIds) {
|
|
125
|
+
if (!xmbMessageIds.has(xtbId)) {
|
|
126
|
+
errors.push({
|
|
127
|
+
code: "INVALID_MESSAGE_REFERENCE",
|
|
128
|
+
message: `XTB contains translation for message ID "${xtbId}" which doesn't exist in XMB source`,
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
catch (error) {
|
|
134
|
+
errors.push({
|
|
135
|
+
code: "REFERENCE_VALIDATION_ERROR",
|
|
136
|
+
message: `Failed to validate message references: ${error instanceof Error ? error.message : String(error)}`,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return {
|
|
140
|
+
isValid: errors.length === 0,
|
|
141
|
+
errors,
|
|
142
|
+
warnings,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
extractPlaceholderInfo(text) {
|
|
146
|
+
const variables = [];
|
|
147
|
+
const phElements = [];
|
|
148
|
+
const examples = [];
|
|
149
|
+
// Extract {$variable} and {VARIABLE} patterns
|
|
150
|
+
const variableMatches = text.match(/\{[^}]+\}/g);
|
|
151
|
+
if (variableMatches) {
|
|
152
|
+
variables.push(...variableMatches);
|
|
153
|
+
}
|
|
154
|
+
// Extract <ph> elements
|
|
155
|
+
const phMatches = text.match(/<ph\s+name="([^"]*)"[^>]*>(.*?)<\/ph>/g);
|
|
156
|
+
if (phMatches) {
|
|
157
|
+
for (const match of phMatches) {
|
|
158
|
+
const nameMatch = match.match(/name="([^"]*)"/);
|
|
159
|
+
const contentMatch = match.match(/>([^<]*)</);
|
|
160
|
+
if (nameMatch && contentMatch) {
|
|
161
|
+
phElements.push({
|
|
162
|
+
name: nameMatch[1],
|
|
163
|
+
content: contentMatch[1],
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
// Extract <ex> elements
|
|
169
|
+
const exMatches = text.match(/<ex>(.*?)<\/ex>/g);
|
|
170
|
+
if (exMatches) {
|
|
171
|
+
for (const match of exMatches) {
|
|
172
|
+
const contentMatch = match.match(/<ex>(.*?)<\/ex>/);
|
|
173
|
+
if (contentMatch) {
|
|
174
|
+
examples.push(contentMatch[1]);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return { variables, phElements, examples };
|
|
179
|
+
}
|
|
180
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { EnhancedTranslationFile, FormatOptions, IFormatHandler, ValidationResult } from "../format.interface.js";
|
|
2
|
+
import type { TranslationFile } from "../translate.interface.js";
|
|
3
|
+
export declare class XmlHandler implements IFormatHandler {
|
|
4
|
+
private parser;
|
|
5
|
+
private builder;
|
|
6
|
+
private builderOptions;
|
|
7
|
+
constructor();
|
|
8
|
+
canHandle(filePath: string, content?: string): boolean;
|
|
9
|
+
parse(content: string): EnhancedTranslationFile;
|
|
10
|
+
serialize(data: EnhancedTranslationFile, options?: FormatOptions): string;
|
|
11
|
+
getFileExtension(): string;
|
|
12
|
+
validateStructure(data: TranslationFile): ValidationResult;
|
|
13
|
+
private detectXmlFormat;
|
|
14
|
+
private transformParsedData;
|
|
15
|
+
private transformAndroidXml;
|
|
16
|
+
private transformIosXml;
|
|
17
|
+
private transformGenericXml;
|
|
18
|
+
private flattenXmlStructure;
|
|
19
|
+
private updateOriginalStructure;
|
|
20
|
+
private updateTranslatedValues;
|
|
21
|
+
private reconstructXmlStructure;
|
|
22
|
+
private validateAndroidFormat;
|
|
23
|
+
private validateIosFormat;
|
|
24
|
+
private validateGenericXmlFormat;
|
|
25
|
+
private validateXmlStructure;
|
|
26
|
+
private looksLikeAndroidXml;
|
|
27
|
+
private looksLikeIosXml;
|
|
28
|
+
}
|