auto-translate-json-library 2.0.2 → 2.1.0
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 +305 -3
- package/build/package.json +31 -16
- package/build/src/bin/cli.d.ts +1 -1
- package/build/src/bin/cli.js +253 -58
- package/build/src/config.d.ts +12 -1
- package/build/src/files.js +2 -2
- package/build/src/format-detector.js +1 -1
- package/build/src/huggingface-local.d.ts +11 -0
- package/build/src/huggingface-local.js +71 -0
- package/build/src/huggingface.d.ts +12 -0
- package/build/src/huggingface.js +76 -0
- package/build/src/index.js +16 -0
- package/build/src/lib.js +10 -26
- package/build/src/openai.js +1 -0
- package/build/src/provider-factory.d.ts +3 -0
- package/build/src/provider-factory.js +38 -0
- package/package.json +31 -16
- package/build/tests/arb-handler.test.d.ts +0 -1
- package/build/tests/arb-handler.test.js +0 -694
- package/build/tests/cli-integration.test.d.ts +0 -1
- package/build/tests/cli-integration.test.js +0 -352
- package/build/tests/csv-handler.test.d.ts +0 -1
- package/build/tests/csv-handler.test.js +0 -507
- package/build/tests/error-handling.test.d.ts +0 -1
- package/build/tests/error-handling.test.js +0 -456
- package/build/tests/files-integration.test.d.ts +0 -1
- package/build/tests/files-integration.test.js +0 -421
- package/build/tests/json-handler.test.d.ts +0 -1
- package/build/tests/json-handler.test.js +0 -526
- package/build/tests/po-handler.test.d.ts +0 -1
- package/build/tests/po-handler.test.js +0 -768
- package/build/tests/properties-handler.test.d.ts +0 -1
- package/build/tests/properties-handler.test.js +0 -316
- package/build/tests/setup.d.ts +0 -1
- package/build/tests/setup.js +0 -5
- package/build/tests/xliff-handler.test.d.ts +0 -1
- package/build/tests/xliff-handler.test.js +0 -459
- package/build/tests/xmb-xtb-handler.test.d.ts +0 -1
- package/build/tests/xmb-xtb-handler.test.js +0 -758
- package/build/tests/xml-handler.test.d.ts +0 -1
- package/build/tests/xml-handler.test.js +0 -570
- package/build/tests/yaml-handler.test.d.ts +0 -1
- package/build/tests/yaml-handler.test.js +0 -156
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
import { YamlHandler } from "../src/format/yaml-handler.js";
|
|
2
|
-
import { fileURLToPath } from 'url';
|
|
3
|
-
import { dirname } from 'path';
|
|
4
|
-
import * as fs from "node:fs";
|
|
5
|
-
import * as path from "node:path";
|
|
6
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
-
const __dirname = dirname(__filename);
|
|
8
|
-
describe("YamlHandler", () => {
|
|
9
|
-
let handler;
|
|
10
|
-
let sampleYamlContent;
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
handler = new YamlHandler();
|
|
13
|
-
sampleYamlContent = fs.readFileSync(path.join(__dirname, "test-data", "sample.yaml"), "utf-8");
|
|
14
|
-
});
|
|
15
|
-
describe("canHandle", () => {
|
|
16
|
-
it("should handle .yaml files", () => {
|
|
17
|
-
expect(handler.canHandle("test.yaml")).toBe(true);
|
|
18
|
-
});
|
|
19
|
-
it("should handle .yml files", () => {
|
|
20
|
-
expect(handler.canHandle("test.yml")).toBe(true);
|
|
21
|
-
});
|
|
22
|
-
it("should not handle other file types", () => {
|
|
23
|
-
expect(handler.canHandle("test.json")).toBe(false);
|
|
24
|
-
expect(handler.canHandle("test.xml")).toBe(false);
|
|
25
|
-
});
|
|
26
|
-
it("should validate YAML content when provided", () => {
|
|
27
|
-
expect(handler.canHandle("test.yaml", "key: value")).toBe(true);
|
|
28
|
-
expect(handler.canHandle("test.yaml", "invalid: yaml: content:")).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
});
|
|
31
|
-
describe("parse", () => {
|
|
32
|
-
it("should parse valid YAML content", () => {
|
|
33
|
-
const result = handler.parse(sampleYamlContent);
|
|
34
|
-
expect(result).toBeDefined();
|
|
35
|
-
expect(result._metadata).toBeDefined();
|
|
36
|
-
expect(result._metadata?.format).toBe("yaml");
|
|
37
|
-
expect(result._metadata?.preserveComments).toBe(true);
|
|
38
|
-
});
|
|
39
|
-
it("should flatten nested structures", () => {
|
|
40
|
-
const result = handler.parse(sampleYamlContent);
|
|
41
|
-
expect(result["app.title"]).toBe("My Application");
|
|
42
|
-
expect(result["navigation.home"]).toBe("Home");
|
|
43
|
-
expect(result["messages.errors.notFound"]).toBe("Page not found");
|
|
44
|
-
});
|
|
45
|
-
it("should preserve non-string values", () => {
|
|
46
|
-
const result = handler.parse(sampleYamlContent);
|
|
47
|
-
expect(result["app.version"]).toBe("1.0.0"); // This is a string in the YAML
|
|
48
|
-
expect(result["app.isActive"]).toBe(true);
|
|
49
|
-
expect(result["settings.notifications.sms"]).toBe(null);
|
|
50
|
-
expect(result["metadata.config.maxUsers"]).toBe(1000); // This is a number
|
|
51
|
-
expect(result["metadata.config.timeout"]).toBe(30.5); // This is a float
|
|
52
|
-
expect(result["metadata.config.debug"]).toBe(false); // This is a boolean
|
|
53
|
-
});
|
|
54
|
-
it("should handle arrays", () => {
|
|
55
|
-
const result = handler.parse(sampleYamlContent);
|
|
56
|
-
expect(result["features[0]"]).toBe("Feature One");
|
|
57
|
-
expect(result["features[1]"]).toBe("Feature Two");
|
|
58
|
-
expect(result["features[2]"]).toBe("Feature Three");
|
|
59
|
-
});
|
|
60
|
-
it("should throw error for invalid YAML", () => {
|
|
61
|
-
expect(() => {
|
|
62
|
-
handler.parse("invalid: yaml: content:");
|
|
63
|
-
}).toThrow("Failed to parse YAML");
|
|
64
|
-
});
|
|
65
|
-
it("should throw error for empty YAML", () => {
|
|
66
|
-
expect(() => {
|
|
67
|
-
handler.parse("");
|
|
68
|
-
}).toThrow("YAML file is empty");
|
|
69
|
-
});
|
|
70
|
-
it("should throw error for array root", () => {
|
|
71
|
-
expect(() => {
|
|
72
|
-
handler.parse("- item1\n- item2");
|
|
73
|
-
}).toThrow("YAML root must be an object");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("serialize", () => {
|
|
77
|
-
it("should serialize flattened data back to YAML", () => {
|
|
78
|
-
const parsed = handler.parse(sampleYamlContent);
|
|
79
|
-
const serialized = handler.serialize(parsed);
|
|
80
|
-
expect(serialized).toContain("app:");
|
|
81
|
-
expect(serialized).toContain("title: My Application");
|
|
82
|
-
expect(serialized).toContain("navigation:");
|
|
83
|
-
expect(serialized).toContain("home: Home");
|
|
84
|
-
});
|
|
85
|
-
it("should preserve non-string values in serialization", () => {
|
|
86
|
-
const parsed = handler.parse(sampleYamlContent);
|
|
87
|
-
const serialized = handler.serialize(parsed);
|
|
88
|
-
expect(serialized).toContain("version: 1.0.0");
|
|
89
|
-
expect(serialized).toContain("isActive: true");
|
|
90
|
-
expect(serialized).toContain("sms: null");
|
|
91
|
-
expect(serialized).toContain("maxUsers: 1000");
|
|
92
|
-
expect(serialized).toContain("timeout: 30.5");
|
|
93
|
-
expect(serialized).toContain("debug: false");
|
|
94
|
-
});
|
|
95
|
-
it("should handle custom formatting options", () => {
|
|
96
|
-
const parsed = handler.parse(sampleYamlContent);
|
|
97
|
-
const serialized = handler.serialize(parsed, { indentation: 4 });
|
|
98
|
-
expect(serialized).toBeDefined();
|
|
99
|
-
expect(typeof serialized).toBe("string");
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
describe("validateStructure", () => {
|
|
103
|
-
it("should validate correct YAML structure", () => {
|
|
104
|
-
const parsed = handler.parse(sampleYamlContent);
|
|
105
|
-
const validation = handler.validateStructure(parsed);
|
|
106
|
-
expect(validation.isValid).toBe(true);
|
|
107
|
-
expect(validation.errors).toHaveLength(0);
|
|
108
|
-
});
|
|
109
|
-
it("should detect invalid structure", () => {
|
|
110
|
-
const validation = handler.validateStructure("not an object");
|
|
111
|
-
expect(validation.isValid).toBe(false);
|
|
112
|
-
expect(validation.errors).toHaveLength(1);
|
|
113
|
-
expect(validation.errors[0].code).toBe("INVALID_STRUCTURE");
|
|
114
|
-
});
|
|
115
|
-
it("should detect array root", () => {
|
|
116
|
-
const validation = handler.validateStructure(["item1", "item2"]);
|
|
117
|
-
expect(validation.isValid).toBe(false);
|
|
118
|
-
expect(validation.errors).toHaveLength(1);
|
|
119
|
-
expect(validation.errors[0].code).toBe("INVALID_ROOT_TYPE");
|
|
120
|
-
});
|
|
121
|
-
it("should warn about non-translatable values", () => {
|
|
122
|
-
const parsed = handler.parse(sampleYamlContent);
|
|
123
|
-
const validation = handler.validateStructure(parsed);
|
|
124
|
-
expect(validation.warnings.length).toBeGreaterThan(0);
|
|
125
|
-
const nonTranslatableWarnings = validation.warnings.filter(w => w.code === "NON_TRANSLATABLE_VALUE_PRESERVED");
|
|
126
|
-
expect(nonTranslatableWarnings.length).toBeGreaterThan(0);
|
|
127
|
-
});
|
|
128
|
-
it("should warn about empty YAML", () => {
|
|
129
|
-
const validation = handler.validateStructure({});
|
|
130
|
-
expect(validation.isValid).toBe(true);
|
|
131
|
-
expect(validation.warnings).toHaveLength(1);
|
|
132
|
-
expect(validation.warnings[0].code).toBe("EMPTY_YAML");
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
describe("getFileExtension", () => {
|
|
136
|
-
it("should return .yaml extension", () => {
|
|
137
|
-
expect(handler.getFileExtension()).toBe(".yaml");
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
describe("round-trip processing", () => {
|
|
141
|
-
it("should maintain data integrity through parse and serialize", () => {
|
|
142
|
-
const original = handler.parse(sampleYamlContent);
|
|
143
|
-
const serialized = handler.serialize(original);
|
|
144
|
-
const reparsed = handler.parse(serialized);
|
|
145
|
-
// Compare translatable string values
|
|
146
|
-
expect(reparsed["app.title"]).toBe(original["app.title"]);
|
|
147
|
-
expect(reparsed["navigation.home"]).toBe(original["navigation.home"]);
|
|
148
|
-
expect(reparsed["messages.errors.notFound"]).toBe(original["messages.errors.notFound"]);
|
|
149
|
-
// Compare non-string values
|
|
150
|
-
expect(reparsed["app.version"]).toBe(original["app.version"]);
|
|
151
|
-
expect(reparsed["app.isActive"]).toBe(original["app.isActive"]);
|
|
152
|
-
expect(reparsed["metadata.config.maxUsers"]).toBe(original["metadata.config.maxUsers"]);
|
|
153
|
-
expect(reparsed["metadata.config.debug"]).toBe(original["metadata.config.debug"]);
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
});
|