lingo-linter-tool 1.0.0 → 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/cli.js CHANGED
@@ -11,7 +11,6 @@ const glob_1 = require("glob");
11
11
  const no_string_concat_1 = require("./linter/rules/no-string-concat");
12
12
  const missing_keys_1 = require("./linter/rules/missing-keys");
13
13
  const healer_1 = require("./healer");
14
- const reporter_1 = require("./utils/reporter");
15
14
  const program = new commander_1.Command();
16
15
  const calculateHealth = (errors, warnings) => {
17
16
  let score = 100 - errors * 5 - warnings * 2;
@@ -60,7 +59,6 @@ program
60
59
  console.log("");
61
60
  });
62
61
  const score = calculateHealth(errorCount, warningCount);
63
- await (0, reporter_1.uploadHealthScore)(score, errorCount, warningCount);
64
62
  const scoreColor = score > 80 ? chalk_1.default.green : score > 50 ? chalk_1.default.yellow : chalk_1.default.red;
65
63
  console.log(chalk_1.default.bold("-----------------------------------"));
66
64
  console.log(`Localization Health: ${scoreColor(score + " / 100")}`);
@@ -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
- const missingKeyIssues = issues.filter((i) => i.ruleId === "missing-keys" && i.key);
57
- if (missingKeyIssues.length === 0) {
58
- console.log("✨ No missing keys to heal.");
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
- const updates = {};
62
- for (const issue of missingKeyIssues) {
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;
@@ -30,32 +30,32 @@ exports.Translator = void 0;
30
30
  const axios_1 = __importDefault(require("axios"));
31
31
  const dotenv = __importStar(require("dotenv"));
32
32
  dotenv.config();
33
- const API_KEY = process.env.LINGO_API_KEY;
34
- const API_URL = "https://api.lingo.dev/v1/translate";
33
+ const API_KEY = process.env.LINGO_API_KEY || process.env.OPENAI_API_KEY;
35
34
  class Translator {
36
35
  static async translate(text, targetLocale) {
37
36
  if (!text)
38
37
  return "";
39
38
  if (!API_KEY) {
40
- console.warn("⚠️ No LINGO_API_KEY found. Using mock mode.");
41
- return `[${targetLocale.toUpperCase()}] ${text}`;
39
+ console.warn("⚠️ MISSING API KEY: Cannot translate. Ensure LINGO_API_KEY is set in GitHub Secrets.");
40
+ return text;
42
41
  }
43
42
  try {
44
- const response = await axios_1.default.post(API_URL, {
43
+ const response = await axios_1.default.post("https://api.lingo.dev/v1/translate", {
45
44
  source: "en",
46
45
  target: targetLocale,
47
46
  content: text,
47
+ context: "UI String",
48
48
  }, {
49
49
  headers: {
50
50
  Authorization: `Bearer ${API_KEY}`,
51
51
  "Content-Type": "application/json",
52
52
  },
53
53
  });
54
- return (response.data.translation ||
55
- response.data.choices[0].message.content);
54
+ return response.data.translation;
56
55
  }
57
56
  catch (error) {
58
- console.error(`❌ API Error translating to ${targetLocale}:`, error);
57
+ const msg = error.response?.data?.message || error.message;
58
+ console.error(`❌ API Error (${targetLocale}): ${msg}`);
59
59
  return text;
60
60
  }
61
61
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lingo-linter-tool",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "Localization linter and self-healing tool",
5
5
  "bin": {
6
6
  "lingo": "./dist/cli.js"