lingo-linter-tool 1.0.1 ā 1.0.3
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 +27 -65
- package/package.json +2 -2
package/dist/healer/index.js
CHANGED
|
@@ -27,78 +27,40 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
exports.healIssues = void 0;
|
|
30
|
+
const child_process_1 = require("child_process");
|
|
30
31
|
const fs = __importStar(require("fs"));
|
|
31
32
|
const path = __importStar(require("path"));
|
|
32
|
-
const translator_1 = require("./translator");
|
|
33
33
|
const chalk_1 = __importDefault(require("chalk"));
|
|
34
|
-
function getSourceText(localesDir, key) {
|
|
35
|
-
try {
|
|
36
|
-
const enPath = path.join(localesDir, "en.json");
|
|
37
|
-
if (!fs.existsSync(enPath))
|
|
38
|
-
return null;
|
|
39
|
-
const raw = fs.readFileSync(enPath, "utf-8");
|
|
40
|
-
const json = JSON.parse(raw);
|
|
41
|
-
const keys = key.split(".");
|
|
42
|
-
let current = json;
|
|
43
|
-
for (const k of keys) {
|
|
44
|
-
if (current[k] === undefined)
|
|
45
|
-
return null;
|
|
46
|
-
current = current[k];
|
|
47
|
-
}
|
|
48
|
-
return typeof current === "string" ? current : null;
|
|
49
|
-
}
|
|
50
|
-
catch (e) {
|
|
51
|
-
return null;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
34
|
async function healIssues(issues, localesDir) {
|
|
55
|
-
console.log(chalk_1.default.blue("\n𩹠Initializing Lingo.dev
|
|
56
|
-
const
|
|
57
|
-
if (
|
|
58
|
-
console.log("⨠No missing keys to heal.");
|
|
35
|
+
console.log(chalk_1.default.blue("\n𩹠Initializing Lingo.dev Official Sync..."));
|
|
36
|
+
const missingKeys = issues.filter((i) => i.ruleId === "missing-keys");
|
|
37
|
+
if (missingKeys.length === 0)
|
|
59
38
|
return;
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.
|
|
69
|
-
continue;
|
|
39
|
+
const enPath = path.join(localesDir, "en.json");
|
|
40
|
+
const enContent = JSON.parse(fs.readFileSync(enPath, "utf-8"));
|
|
41
|
+
let hasChanges = false;
|
|
42
|
+
missingKeys.forEach((issue) => {
|
|
43
|
+
if (issue.key && !enContent[issue.key]) {
|
|
44
|
+
const humanText = issue.key.split(".").pop() || issue.key;
|
|
45
|
+
enContent[issue.key] = humanText;
|
|
46
|
+
hasChanges = true;
|
|
47
|
+
console.log(chalk_1.default.gray(` ā Added source key: "${issue.key}"`));
|
|
70
48
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
const translation = await translator_1.Translator.translate(sourceText, targetLang);
|
|
75
|
-
console.log(chalk_1.default.green("Done"));
|
|
76
|
-
updates[targetFile][key] = translation;
|
|
49
|
+
});
|
|
50
|
+
if (hasChanges) {
|
|
51
|
+
fs.writeFileSync(enPath, JSON.stringify(enContent, null, 2));
|
|
77
52
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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;
|
|
53
|
+
try {
|
|
54
|
+
console.log(chalk_1.default.magenta("š Triggering 'npx lingo.dev run' to generate translations..."));
|
|
55
|
+
(0, child_process_1.execSync)("npx lingo.dev run --force", {
|
|
56
|
+
stdio: "inherit",
|
|
57
|
+
cwd: path.dirname(localesDir),
|
|
99
58
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
59
|
+
console.log(chalk_1.default.green("\nā
Lingo.dev successfully healed your files!"));
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.error(chalk_1.default.red("ā Failed to run Lingo.dev CLI. Is it installed in the target app?"));
|
|
63
|
+
console.error(chalk_1.default.yellow("š Try running: npm install -D lingo.dev"));
|
|
64
|
+
}
|
|
103
65
|
}
|
|
104
66
|
exports.healIssues = healIssues;
|
package/package.json
CHANGED