lingo-linter-tool 1.0.3 ā 1.0.5
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 +33 -9
- package/package.json +1 -1
package/dist/healer/index.js
CHANGED
|
@@ -32,35 +32,59 @@ const fs = __importStar(require("fs"));
|
|
|
32
32
|
const path = __importStar(require("path"));
|
|
33
33
|
const chalk_1 = __importDefault(require("chalk"));
|
|
34
34
|
async function healIssues(issues, localesDir) {
|
|
35
|
-
console.log(chalk_1.default.blue("\n𩹠Initializing Lingo.dev
|
|
35
|
+
console.log(chalk_1.default.blue("\n𩹠Initializing Lingo.dev Integration..."));
|
|
36
36
|
const missingKeys = issues.filter((i) => i.ruleId === "missing-keys");
|
|
37
37
|
if (missingKeys.length === 0)
|
|
38
38
|
return;
|
|
39
|
+
const projectRoot = path.dirname(localesDir);
|
|
40
|
+
const configPath = path.join(projectRoot, "i18n.json");
|
|
41
|
+
if (!fs.existsSync(configPath)) {
|
|
42
|
+
console.log(chalk_1.default.yellow("ā ļø i18n.json not found. Auto-generating default config..."));
|
|
43
|
+
const defaultConfig = {
|
|
44
|
+
source: "en",
|
|
45
|
+
targets: ["fr", "de"],
|
|
46
|
+
buckets: [
|
|
47
|
+
{
|
|
48
|
+
path: "./" + path.basename(localesDir),
|
|
49
|
+
pattern: "{locale}.json",
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
provider: "openai",
|
|
53
|
+
};
|
|
54
|
+
fs.writeFileSync(configPath, JSON.stringify(defaultConfig, null, 2));
|
|
55
|
+
console.log(chalk_1.default.green("ā
Created valid i18n.json with buckets"));
|
|
56
|
+
}
|
|
39
57
|
const enPath = path.join(localesDir, "en.json");
|
|
40
|
-
|
|
58
|
+
let enContent = {};
|
|
59
|
+
try {
|
|
60
|
+
enContent = JSON.parse(fs.readFileSync(enPath, "utf-8"));
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
}
|
|
41
64
|
let hasChanges = false;
|
|
42
65
|
missingKeys.forEach((issue) => {
|
|
43
66
|
if (issue.key && !enContent[issue.key]) {
|
|
44
67
|
const humanText = issue.key.split(".").pop() || issue.key;
|
|
45
|
-
|
|
68
|
+
const formattedText = humanText.charAt(0).toUpperCase() + humanText.slice(1);
|
|
69
|
+
enContent[issue.key] = formattedText;
|
|
46
70
|
hasChanges = true;
|
|
47
|
-
console.log(chalk_1.default.gray(` ā Added source key: "${issue.key}"`));
|
|
48
71
|
}
|
|
49
72
|
});
|
|
50
73
|
if (hasChanges) {
|
|
51
74
|
fs.writeFileSync(enPath, JSON.stringify(enContent, null, 2));
|
|
75
|
+
console.log(chalk_1.default.gray(` ā Injected ${missingKeys.length} missing keys into en.json`));
|
|
52
76
|
}
|
|
53
77
|
try {
|
|
54
|
-
console.log(chalk_1.default.magenta("š Triggering
|
|
78
|
+
console.log(chalk_1.default.magenta("š Triggering Lingo.dev AI Translation..."));
|
|
55
79
|
(0, child_process_1.execSync)("npx lingo.dev run --force", {
|
|
56
80
|
stdio: "inherit",
|
|
57
|
-
cwd:
|
|
81
|
+
cwd: projectRoot,
|
|
58
82
|
});
|
|
59
|
-
console.log(chalk_1.default.green("\nā
|
|
83
|
+
console.log(chalk_1.default.green("\nā
Auto-Healing Complete!"));
|
|
60
84
|
}
|
|
61
85
|
catch (error) {
|
|
62
|
-
console.error(chalk_1.default.red("ā Failed to run
|
|
63
|
-
console.error(chalk_1.default.yellow("
|
|
86
|
+
console.error(chalk_1.default.red("\nā Failed to run lingo.dev CLI."));
|
|
87
|
+
console.error(chalk_1.default.yellow(" Ensure you have an OpenAI API Key in your .env or GitHub Secrets."));
|
|
64
88
|
}
|
|
65
89
|
}
|
|
66
90
|
exports.healIssues = healIssues;
|