@scoutello/i18n-magic 0.53.0 → 0.54.0
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/README.md +236 -266
- package/dist/lib/utils.d.ts +5 -4
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +49 -37
- package/dist/lib/utils.js.map +1 -1
- package/dist/mcp-server.js +29 -15
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/utils.ts +55 -38
- package/src/mcp-server.ts +31 -15
package/src/mcp-server.ts
CHANGED
|
@@ -67,7 +67,8 @@ function resolveProjectRoot(): string {
|
|
|
67
67
|
// Zod schema for the add_translation_key tool parameters
|
|
68
68
|
const AddTranslationKeySchema = z.object({
|
|
69
69
|
key: z.string().describe("The translation key to add (e.g., \"welcomeMessage\")"),
|
|
70
|
-
value: z.string().describe("The
|
|
70
|
+
value: z.string().describe("The text value for this translation key"),
|
|
71
|
+
language: z.string().optional().describe("The language code of the provided value (e.g., \"en\", \"de\", \"fr\"). Defaults to \"en\" (English) if not specified."),
|
|
71
72
|
})
|
|
72
73
|
|
|
73
74
|
// Zod schema for the list_untranslated_keys tool parameters
|
|
@@ -94,7 +95,8 @@ const GetTranslationKeySchema = z.object({
|
|
|
94
95
|
// Zod schema for the update_translation_key tool parameters
|
|
95
96
|
const UpdateTranslationKeySchema = z.object({
|
|
96
97
|
key: z.string().describe("The translation key to update (e.g., \"welcomeMessage\")"),
|
|
97
|
-
value: z.string().describe("The new
|
|
98
|
+
value: z.string().describe("The new text value for this translation key"),
|
|
99
|
+
language: z.string().optional().describe("The language code of the provided value (e.g., \"en\", \"de\", \"fr\"). Defaults to \"en\" (English) if not specified."),
|
|
98
100
|
namespace: z
|
|
99
101
|
.string()
|
|
100
102
|
.optional()
|
|
@@ -182,7 +184,7 @@ class I18nMagicServer {
|
|
|
182
184
|
tools: [
|
|
183
185
|
{
|
|
184
186
|
name: "add_translation_key",
|
|
185
|
-
description: "Add a new translation key with
|
|
187
|
+
description: "Add a new translation key with a text value. You can optionally specify the language of the value you're providing (defaults to English).",
|
|
186
188
|
inputSchema: {
|
|
187
189
|
type: "object",
|
|
188
190
|
properties: {
|
|
@@ -194,7 +196,12 @@ class I18nMagicServer {
|
|
|
194
196
|
value: {
|
|
195
197
|
type: "string",
|
|
196
198
|
description:
|
|
197
|
-
"The
|
|
199
|
+
"The text value for this translation key",
|
|
200
|
+
},
|
|
201
|
+
language: {
|
|
202
|
+
type: "string",
|
|
203
|
+
description:
|
|
204
|
+
"The language code of the provided value (e.g., \"en\" for English, \"de\" for German, \"fr\" for French). Defaults to \"en\" if not specified.",
|
|
198
205
|
},
|
|
199
206
|
},
|
|
200
207
|
required: ["key", "value"],
|
|
@@ -240,7 +247,7 @@ class I18nMagicServer {
|
|
|
240
247
|
{
|
|
241
248
|
name: "update_translation_key",
|
|
242
249
|
description:
|
|
243
|
-
"Update an existing translation key with a new
|
|
250
|
+
"Update an existing translation key with a new text value. You can optionally specify the language of the value you're providing (defaults to English). This will update the key across all locales (translating automatically to other languages) and all namespaces where the key exists. Use this when you need to fix typos, improve wording, or change the text of an existing translation. If you're not sure if a key exists, use get_translation_key or search_translations first.",
|
|
244
251
|
inputSchema: {
|
|
245
252
|
type: "object",
|
|
246
253
|
properties: {
|
|
@@ -252,7 +259,12 @@ class I18nMagicServer {
|
|
|
252
259
|
value: {
|
|
253
260
|
type: "string",
|
|
254
261
|
description:
|
|
255
|
-
"The new
|
|
262
|
+
"The new text value for this translation key",
|
|
263
|
+
},
|
|
264
|
+
language: {
|
|
265
|
+
type: "string",
|
|
266
|
+
description:
|
|
267
|
+
"The language code of the provided value (e.g., \"en\" for English, \"de\" for German, \"fr\" for French). Defaults to \"en\" if not specified.",
|
|
256
268
|
},
|
|
257
269
|
namespace: {
|
|
258
270
|
type: "string",
|
|
@@ -311,6 +323,7 @@ class I18nMagicServer {
|
|
|
311
323
|
result = await addTranslationKey({
|
|
312
324
|
key: params.key,
|
|
313
325
|
value: params.value,
|
|
326
|
+
language: params.language || "en",
|
|
314
327
|
config,
|
|
315
328
|
})
|
|
316
329
|
} finally {
|
|
@@ -325,14 +338,15 @@ class I18nMagicServer {
|
|
|
325
338
|
text: JSON.stringify(
|
|
326
339
|
{
|
|
327
340
|
success: true,
|
|
328
|
-
message: `Successfully added translation key "${result.key}" to affected namespaces: ${result.namespace} (${result.locale})`,
|
|
341
|
+
message: `Successfully added translation key "${result.key}" to affected namespaces: ${result.namespace} (locales: ${result.locale})`,
|
|
329
342
|
key: result.key,
|
|
330
343
|
value: result.value,
|
|
344
|
+
providedLanguage: params.language || "en",
|
|
331
345
|
namespace: result.namespace,
|
|
332
|
-
|
|
346
|
+
locales: result.locale,
|
|
333
347
|
nextStep: result.locale.includes(',')
|
|
334
|
-
? "
|
|
335
|
-
: "
|
|
348
|
+
? "Key was automatically translated to multiple locales"
|
|
349
|
+
: "Run 'i18n-magic sync' to translate this key to other locales",
|
|
336
350
|
diagnostics: logMessages.join('\n'),
|
|
337
351
|
},
|
|
338
352
|
null,
|
|
@@ -681,20 +695,21 @@ class I18nMagicServer {
|
|
|
681
695
|
}
|
|
682
696
|
|
|
683
697
|
// Build translation cache with new value
|
|
698
|
+
const inputLanguage = params.language || "en"
|
|
684
699
|
const translationCache: Record<string, string> = {
|
|
685
|
-
|
|
700
|
+
[inputLanguage]: params.value,
|
|
686
701
|
}
|
|
687
702
|
|
|
688
703
|
// Translate to all other locales
|
|
689
|
-
const
|
|
690
|
-
if (
|
|
704
|
+
const otherLocales = config.locales.filter((l) => l !== inputLanguage)
|
|
705
|
+
if (otherLocales.length > 0 && config.openai) {
|
|
691
706
|
const { translateKey } = await import("./lib/utils.js")
|
|
692
707
|
|
|
693
708
|
await Promise.all(
|
|
694
|
-
|
|
709
|
+
otherLocales.map(async (locale) => {
|
|
695
710
|
const translation = await translateKey({
|
|
696
711
|
context: config.context || "",
|
|
697
|
-
inputLanguage:
|
|
712
|
+
inputLanguage: inputLanguage,
|
|
698
713
|
outputLanguage: locale,
|
|
699
714
|
object: {
|
|
700
715
|
[params.key]: params.value,
|
|
@@ -730,6 +745,7 @@ class I18nMagicServer {
|
|
|
730
745
|
message: `Successfully updated translation key "${params.key}" in ${targetNamespaces.length} namespace(s) and ${config.locales.length} locale(s)`,
|
|
731
746
|
key: params.key,
|
|
732
747
|
newValue: params.value,
|
|
748
|
+
providedLanguage: params.language || "en",
|
|
733
749
|
namespaces: targetNamespaces,
|
|
734
750
|
locales: config.locales,
|
|
735
751
|
diagnostics: logMessages.join('\n'),
|