@elyracode/i18n-tools 0.9.56 → 0.9.58

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.
Files changed (2) hide show
  1. package/extensions/index.ts +42 -19
  2. package/package.json +1 -1
@@ -1,10 +1,21 @@
1
- import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
1
+ import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import { extname, join, relative } from "node:path";
3
- import type { ExtensionAPI } from "@elyracode/coding-agent";
3
+ import type { AgentToolResult, ExtensionAPI } from "@elyracode/coding-agent";
4
4
  import { Type } from "typebox";
5
5
 
6
- export default function (elyra: ExtensionAPI): void {
6
+ /** Details reported by find_hardcoded_strings. */
7
+ interface HardcodedStringsDetails {
8
+ count?: number;
9
+ files?: number;
10
+ }
11
+
12
+ /** Details reported by find_missing_translations. */
13
+ interface MissingTranslationsDetails {
14
+ totalMissing?: number;
15
+ locales?: number;
16
+ }
7
17
 
18
+ export default function (elyra: ExtensionAPI): void {
8
19
  // ── Tool: find_hardcoded_strings ──
9
20
  elyra.registerTool({
10
21
  name: "find_hardcoded_strings",
@@ -14,16 +25,14 @@ export default function (elyra: ExtensionAPI): void {
14
25
  "that should be translated. Finds strings in templates, labels, placeholders, " +
15
26
  "error messages, and button text. Ignores code-only strings.",
16
27
  parameters: Type.Object({
17
- path: Type.Optional(
18
- Type.String({ description: "Directory to scan (default: resources/)" }),
19
- ),
28
+ path: Type.Optional(Type.String({ description: "Directory to scan (default: resources/)" })),
20
29
  format: Type.Optional(
21
30
  Type.Union([Type.Literal("blade"), Type.Literal("vue"), Type.Literal("react"), Type.Literal("auto")], {
22
31
  description: "File format to scan (default: auto-detect)",
23
32
  }),
24
33
  ),
25
34
  }),
26
- execute: async (_toolCallId, params) => {
35
+ execute: async (_toolCallId, params): Promise<AgentToolResult<HardcodedStringsDetails>> => {
27
36
  try {
28
37
  const cwd = process.cwd();
29
38
  const scanPath = params.path ?? "resources";
@@ -120,11 +129,9 @@ export default function (elyra: ExtensionAPI): void {
120
129
  "Scans lang/ directory for PHP and JSON translation files. " +
121
130
  "Reports keys that exist in one locale but not another.",
122
131
  parameters: Type.Object({
123
- base_locale: Type.Optional(
124
- Type.String({ description: "Base locale to compare against (default: 'en')" }),
125
- ),
132
+ base_locale: Type.Optional(Type.String({ description: "Base locale to compare against (default: 'en')" })),
126
133
  }),
127
- execute: async (_toolCallId, params) => {
134
+ execute: async (_toolCallId, params): Promise<AgentToolResult<MissingTranslationsDetails>> => {
128
135
  try {
129
136
  const cwd = process.cwd();
130
137
  const baseLocale = params.base_locale ?? "en";
@@ -132,7 +139,9 @@ export default function (elyra: ExtensionAPI): void {
132
139
 
133
140
  if (!existsSync(langDir)) {
134
141
  return {
135
- content: [{ type: "text", text: "No lang/ directory found. Laravel translation files should be at lang/." }],
142
+ content: [
143
+ { type: "text", text: "No lang/ directory found. Laravel translation files should be at lang/." },
144
+ ],
136
145
  details: {},
137
146
  };
138
147
  }
@@ -216,17 +225,23 @@ export default function (elyra: ExtensionAPI): void {
216
225
  elyra.registerCommand("i18n", {
217
226
  description: "Find hardcoded strings and missing translations",
218
227
  handler: async (_args, _ctx) => {
219
- elyra.sendUserMessage("Scan this project for i18n issues: find hardcoded strings that need translation and check for missing translation keys across locales.");
228
+ elyra.sendUserMessage(
229
+ "Scan this project for i18n issues: find hardcoded strings that need translation and check for missing translation keys across locales.",
230
+ );
220
231
  },
221
232
  });
222
233
  }
223
234
 
224
235
  function getExtensionsForFormat(format: string): string[] {
225
236
  switch (format) {
226
- case "blade": return [".blade.php"];
227
- case "vue": return [".vue"];
228
- case "react": return [".tsx", ".jsx"];
229
- default: return [".blade.php", ".vue", ".tsx", ".jsx", ".php"];
237
+ case "blade":
238
+ return [".blade.php"];
239
+ case "vue":
240
+ return [".vue"];
241
+ case "react":
242
+ return [".tsx", ".jsx"];
243
+ default:
244
+ return [".blade.php", ".vue", ".tsx", ".jsx", ".php"];
230
245
  }
231
246
  }
232
247
 
@@ -242,7 +257,9 @@ function scanDirectory(dir: string, callback: (path: string) => void): void {
242
257
  callback(full);
243
258
  }
244
259
  }
245
- } catch { /* permission errors */ }
260
+ } catch {
261
+ /* permission errors */
262
+ }
246
263
  }
247
264
 
248
265
  function findHardcodedInLine(line: string, _ext: string): string[] {
@@ -252,7 +269,13 @@ function findHardcodedInLine(line: string, _ext: string): string[] {
252
269
  // Skip comments, imports, variables, code-only lines
253
270
  if (trimmed.startsWith("//") || trimmed.startsWith("*") || trimmed.startsWith("/*")) return results;
254
271
  if (trimmed.startsWith("use ") || trimmed.startsWith("import ")) return results;
255
- if (trimmed.startsWith("$") || trimmed.startsWith("const ") || trimmed.startsWith("let ") || trimmed.startsWith("var ")) return results;
272
+ if (
273
+ trimmed.startsWith("$") ||
274
+ trimmed.startsWith("const ") ||
275
+ trimmed.startsWith("let ") ||
276
+ trimmed.startsWith("var ")
277
+ )
278
+ return results;
256
279
 
257
280
  // Find strings in HTML-like contexts (labels, placeholders, button text, headings)
258
281
  const htmlStringPattern = /(?:>|label="|placeholder="|title="|alt="|aria-label=")([A-Z][^"<>{}\n]{2,60})/g;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elyracode/i18n-tools",
3
- "version": "0.9.56",
3
+ "version": "0.9.58",
4
4
  "description": "Elyra extension for localization -- find hardcoded strings, extract translations, detect missing keys",
5
5
  "type": "module",
6
6
  "keywords": [