lingo-linter-tool 1.0.1 → 1.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/dist/healer/index.js +9 -45
- package/package.json +1 -1
package/dist/healer/index.js
CHANGED
|
@@ -29,8 +29,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.healIssues = void 0;
|
|
30
30
|
const fs = __importStar(require("fs"));
|
|
31
31
|
const path = __importStar(require("path"));
|
|
32
|
-
const translator_1 = require("./translator");
|
|
33
32
|
const chalk_1 = __importDefault(require("chalk"));
|
|
33
|
+
const child_process_1 = require("child_process");
|
|
34
34
|
function getSourceText(localesDir, key) {
|
|
35
35
|
try {
|
|
36
36
|
const enPath = path.join(localesDir, "en.json");
|
|
@@ -53,52 +53,16 @@ function getSourceText(localesDir, key) {
|
|
|
53
53
|
}
|
|
54
54
|
async function healIssues(issues, localesDir) {
|
|
55
55
|
console.log(chalk_1.default.blue("\n🩹 Initializing Lingo.dev Auto-Healer..."));
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
try {
|
|
57
|
+
console.log("🚀 Triggering Lingo.dev CLI Sync...");
|
|
58
|
+
(0, child_process_1.execSync)(`npx lingo sync --locales ${localesDir}`, {
|
|
59
|
+
stdio: "inherit",
|
|
60
|
+
});
|
|
61
|
+
console.log("✅Lingo Sync Complete.");
|
|
59
62
|
return;
|
|
60
63
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const targetFile = path.basename(issue.file);
|
|
64
|
-
const targetLang = targetFile.replace(".json", "");
|
|
65
|
-
const key = issue.key;
|
|
66
|
-
const sourceText = getSourceText(localesDir, key);
|
|
67
|
-
if (!sourceText) {
|
|
68
|
-
console.warn(chalk_1.default.yellow(`⚠️ Skipping "${key}": Key also missing in en.json (Source)`));
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (!updates[targetFile])
|
|
72
|
-
updates[targetFile] = {};
|
|
73
|
-
process.stdout.write(` ✨ Translating "${key}" to ${targetLang}... `);
|
|
74
|
-
const translation = await translator_1.Translator.translate(sourceText, targetLang);
|
|
75
|
-
console.log(chalk_1.default.green("Done"));
|
|
76
|
-
updates[targetFile][key] = translation;
|
|
64
|
+
catch (e) {
|
|
65
|
+
console.error("❌ Lingo CLI failed:", e);
|
|
77
66
|
}
|
|
78
|
-
Object.keys(updates).forEach((file) => {
|
|
79
|
-
if (Object.keys(updates[file]).length === 0)
|
|
80
|
-
return;
|
|
81
|
-
const filePath = path.join(localesDir, file);
|
|
82
|
-
let currentContent = {};
|
|
83
|
-
try {
|
|
84
|
-
currentContent = JSON.parse(fs.readFileSync(filePath, "utf-8"));
|
|
85
|
-
}
|
|
86
|
-
catch (e) {
|
|
87
|
-
}
|
|
88
|
-
const newContent = { ...currentContent };
|
|
89
|
-
Object.entries(updates[file]).forEach(([key, val]) => {
|
|
90
|
-
const parts = key.split(".");
|
|
91
|
-
let current = newContent;
|
|
92
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
93
|
-
const part = parts[i];
|
|
94
|
-
if (!current[part])
|
|
95
|
-
current[part] = {};
|
|
96
|
-
current = current[part];
|
|
97
|
-
}
|
|
98
|
-
current[parts[parts.length - 1]] = val;
|
|
99
|
-
});
|
|
100
|
-
fs.writeFileSync(filePath, JSON.stringify(newContent, null, 2));
|
|
101
|
-
console.log(chalk_1.default.magenta(`💾 Written ${Object.keys(updates[file]).length} new keys to ${file}`));
|
|
102
|
-
});
|
|
103
67
|
}
|
|
104
68
|
exports.healIssues = healIssues;
|