@scoutello/i18n-magic 0.53.0 → 0.55.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 +32 -4
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +183 -73
- package/dist/lib/utils.js.map +1 -1
- package/dist/mcp-server.js +174 -16
- package/dist/mcp-server.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/utils.ts +234 -89
- package/src/mcp-server.ts +198 -16
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
**The intelligent CLI toolkit that automates your internationalization workflow with AI-powered translations.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Stop context switching. Let AI handle your translations while you stay in your code editor.
|
|
6
6
|
|
|
7
7
|
## 🚀 What it does
|
|
8
8
|
|
|
@@ -19,373 +19,343 @@ i18n Magic streamlines the entire translation management process for your JavaSc
|
|
|
19
19
|
- Node.js 16+
|
|
20
20
|
- An OpenAI or Google Gemini API key
|
|
21
21
|
|
|
22
|
-
##
|
|
22
|
+
## Why This Matters
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
**Traditional workflow**: 40+ minutes and 13 context switches to add 10 keys across 4 languages.
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
npm install -g @scoutello/i18n-magic
|
|
28
|
-
# or use directly with npx
|
|
29
|
-
npx @scoutello/i18n-magic
|
|
30
|
-
```
|
|
26
|
+
**With i18n-magic + AI agents**: 2.5 minutes, zero context switches. Stay in flow.
|
|
31
27
|
|
|
32
|
-
|
|
28
|
+
---
|
|
33
29
|
|
|
34
|
-
|
|
30
|
+
## CLI Commands
|
|
35
31
|
|
|
36
32
|
```bash
|
|
37
|
-
#
|
|
38
|
-
|
|
39
|
-
#
|
|
40
|
-
|
|
33
|
+
npx @scoutello/i18n-magic scan # Find & add missing translations
|
|
34
|
+
npx @scoutello/i18n-magic sync # Translate to all languages
|
|
35
|
+
npx @scoutello/i18n-magic replace [key] # Update existing translation
|
|
36
|
+
npx @scoutello/i18n-magic clean # Remove unused keys
|
|
37
|
+
npx @scoutello/i18n-magic check-missing # CI/CD validation
|
|
41
38
|
```
|
|
42
39
|
|
|
43
|
-
|
|
40
|
+
**`scan`** - Scans your codebase for missing keys, prompts you for values, auto-translates to all locales.
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
**`sync`** - Takes your default locale translations and translates missing keys to other locales. Perfect for CI/CD.
|
|
46
43
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
{
|
|
63
|
-
pattern: './apps/mobile/**/*.tsx',
|
|
64
|
-
namespaces: ['mobile'],
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
pattern: './apps/mobile/**/*.ts',
|
|
68
|
-
namespaces: ['mobile'],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
loadPath: 'locales/{{lng}}/{{ns}}.json',
|
|
72
|
-
savePath: 'locales/{{lng}}/{{ns}}.json',
|
|
73
|
-
locales: ['en', 'de'],
|
|
74
|
-
defaultLocale: 'de',
|
|
75
|
-
defaultNamespace: 'common',
|
|
76
|
-
namespaces: ['common', 'forms', 'dashboard', 'mobile'],
|
|
77
|
-
context:
|
|
78
|
-
'This is a context which increases the quality of the translations by giving context to the LLM',
|
|
79
|
-
// Optional configurations
|
|
80
|
-
model: 'gemini-2.0-flash-lite', // or any OpenAI/Gemini model like 'gpt-4.1-mini'
|
|
81
|
-
OPENAI_API_KEY: '.', // Alternative to using .env file
|
|
82
|
-
GEMINI_API_KEY: '', // Alternative to using .env file
|
|
83
|
-
disableTranslationDuringScan: false, // Set to true to skip automatic translations during the scan step. Useful if you want to sync the other languages during CI/CD using sync.
|
|
84
|
-
autoClear: true, // When using the scan command, always run the clean before
|
|
85
|
-
};
|
|
44
|
+
**`replace`** - Update an existing translation key across all locales. Detects which namespaces use the key automatically.
|
|
45
|
+
|
|
46
|
+
**`clean`** - Removes unused translation keys from all locales. Great for keeping files lean.
|
|
47
|
+
|
|
48
|
+
**`check-missing`** - Dry-run check. Exits with error code if translations are missing. Perfect for CI pipelines.
|
|
49
|
+
|
|
50
|
+
### Namespace Organization (for large apps)
|
|
51
|
+
|
|
52
|
+
```javascript
|
|
53
|
+
// i18n-magic.js
|
|
54
|
+
globPatterns: [
|
|
55
|
+
'./src/shared/**/*.tsx', // → common.json
|
|
56
|
+
{ pattern: './src/dashboard/**/*.tsx', namespaces: ['dashboard'] },
|
|
57
|
+
{ pattern: './src/mobile/**/*.tsx', namespaces: ['mobile'] }
|
|
58
|
+
]
|
|
86
59
|
```
|
|
87
60
|
|
|
88
|
-
|
|
61
|
+
Result: Separate files per feature (`common.json`, `dashboard.json`, `mobile.json`) across all locales.
|
|
89
62
|
|
|
90
|
-
|
|
63
|
+
---
|
|
91
64
|
|
|
92
|
-
|
|
65
|
+
## The MCP Server: AI Superpowers
|
|
93
66
|
|
|
94
|
-
|
|
95
|
-
'./components/**/*.tsx';
|
|
96
|
-
```
|
|
67
|
+
**MCP (Model Context Protocol)** = API for AI agents.
|
|
97
68
|
|
|
98
|
-
|
|
99
|
-
```js
|
|
100
|
-
{
|
|
101
|
-
pattern: './apps/dashboard/**/*.tsx',
|
|
102
|
-
namespaces: ['dashboard']
|
|
103
|
-
}
|
|
104
|
-
```
|
|
69
|
+
Install the i18n-magic MCP server in Cursor, and your AI gets 5 new tools:
|
|
105
70
|
|
|
106
|
-
|
|
71
|
+
### 1. `search_translations` - Prevent Duplicates
|
|
72
|
+
Fuzzy search across all translations. AI searches before adding anything.
|
|
107
73
|
|
|
108
|
-
###
|
|
74
|
+
### 2. `add_translation_key` - Add New Keys
|
|
75
|
+
Adds key to English (`en`) locale. Run `sync` afterward to translate to other languages.
|
|
109
76
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
npx @scoutello/i18n-magic scan
|
|
77
|
+
### 3. `get_translation_key` - Check What Exists
|
|
78
|
+
Retrieve current value for any key.
|
|
113
79
|
|
|
114
|
-
|
|
115
|
-
|
|
80
|
+
### 4. `update_translation_key` - Fix & Auto-Translate
|
|
81
|
+
Update a key and **instantly translate to all languages**. No sync needed!
|
|
116
82
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```
|
|
83
|
+
### 5. `list_untranslated_keys` - Batch Check
|
|
84
|
+
Show all missing keys across your codebase.
|
|
120
85
|
|
|
121
|
-
|
|
86
|
+
---
|
|
122
87
|
|
|
123
|
-
|
|
88
|
+
## Quick Setup (5 Minutes)
|
|
124
89
|
|
|
125
|
-
|
|
90
|
+
### 1. Install
|
|
126
91
|
|
|
127
|
-
```
|
|
128
|
-
|
|
92
|
+
```bash
|
|
93
|
+
npm install @scoutello/i18n-magic
|
|
94
|
+
```
|
|
129
95
|
|
|
130
|
-
|
|
131
|
-
region: process.env.S3_REGION,
|
|
132
|
-
credentials: {
|
|
133
|
-
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
134
|
-
secretAccessKey: process.env.S3_SECRET_KEY,
|
|
135
|
-
},
|
|
136
|
-
})
|
|
96
|
+
### 2. Create `i18n-magic.js` in project root
|
|
137
97
|
|
|
98
|
+
```javascript
|
|
138
99
|
module.exports = {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
// Example: Save to S3
|
|
156
|
-
await s3Client.send(
|
|
157
|
-
new PutObjectCommand({
|
|
158
|
-
Bucket: 'my-translations-bucket',
|
|
159
|
-
Key: `locales/${locale}/${namespace}.json`,
|
|
160
|
-
Body: JSON.stringify(data, null, 2),
|
|
161
|
-
ContentType: 'application/json',
|
|
162
|
-
})
|
|
163
|
-
);
|
|
164
|
-
},
|
|
165
|
-
};
|
|
100
|
+
globPatterns: ['./src/**/*.{ts,tsx,js,jsx}'],
|
|
101
|
+
loadPath: 'locales/{{lng}}/{{ns}}.json',
|
|
102
|
+
savePath: 'locales/{{lng}}/{{ns}}.json',
|
|
103
|
+
locales: ['en', 'de', 'es', 'fr'],
|
|
104
|
+
defaultLocale: 'en',
|
|
105
|
+
namespaces: ['common'],
|
|
106
|
+
defaultNamespace: 'common',
|
|
107
|
+
context: 'Your app description here',
|
|
108
|
+
model: 'gpt-4o-mini', // or 'gemini-2.0-flash-lite'
|
|
109
|
+
|
|
110
|
+
// Optional: Auto-clean before scanning
|
|
111
|
+
autoClear: true,
|
|
112
|
+
|
|
113
|
+
// Optional: Skip translation during scan (translate later with sync)
|
|
114
|
+
disableTranslationDuringScan: false,
|
|
115
|
+
}
|
|
166
116
|
```
|
|
167
117
|
|
|
168
|
-
|
|
118
|
+
**Key options**:
|
|
119
|
+
- `context`: Describe your app/domain. Better context = better translations.
|
|
120
|
+
- `autoClear`: Auto-remove unused keys before scanning.
|
|
121
|
+
- `disableTranslationDuringScan`: Set `true` to only add English during scan, then use `sync` command for translations.
|
|
169
122
|
|
|
170
|
-
|
|
123
|
+
### 3. Add API key to `.env`
|
|
171
124
|
|
|
172
125
|
```bash
|
|
173
|
-
|
|
126
|
+
OPENAI_API_KEY=sk-your-key-here
|
|
174
127
|
```
|
|
175
128
|
|
|
176
|
-
###
|
|
129
|
+
### 4. Configure MCP in Cursor
|
|
130
|
+
|
|
131
|
+
Settings → Features → Model Context Protocol:
|
|
177
132
|
|
|
178
|
-
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"i18n-magic": {
|
|
136
|
+
"command": "node",
|
|
137
|
+
"args": ["./node_modules/@scoutello/i18n-magic/dist/mcp-server.js"]
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
179
141
|
|
|
180
|
-
|
|
142
|
+
### 5. Restart Cursor
|
|
181
143
|
|
|
182
|
-
|
|
183
|
-
2. Automatically determine which namespaces each key belongs to based on the file location
|
|
184
|
-
3. Identify missing translation keys in your default locale
|
|
185
|
-
4. Prompt you to provide translations for each missing key
|
|
186
|
-
5. Automatically translate to all other configured locales using AI
|
|
187
|
-
6. Save the new translations to the appropriate namespace files
|
|
144
|
+
Done! Test by asking: *"Search for translations with 'password'"*
|
|
188
145
|
|
|
189
|
-
|
|
146
|
+
---
|
|
190
147
|
|
|
191
|
-
|
|
192
|
-
- Ensuring all translation keys have corresponding values
|
|
193
|
-
- Maintaining translation consistency across locales
|
|
194
|
-
- Automatically organizing translations into the correct namespaces
|
|
148
|
+
## How to Use It
|
|
195
149
|
|
|
196
|
-
###
|
|
150
|
+
### Pattern 1: Adding Translations (Search First!)
|
|
197
151
|
|
|
198
|
-
|
|
152
|
+
**You**: "Add a submit button"
|
|
199
153
|
|
|
200
|
-
|
|
154
|
+
**AI**:
|
|
155
|
+
1. Searches existing translations for "submit"
|
|
156
|
+
2. Finds `submitButton: "Submit"` already exists
|
|
157
|
+
3. Suggests reusing it
|
|
158
|
+
4. Generates: `<Button>{t('submitButton')}</Button>`
|
|
201
159
|
|
|
202
|
-
|
|
203
|
-
2. Prompt you to select or specify the translation key to replace
|
|
204
|
-
3. Ask for the new translation value in your default locale
|
|
205
|
-
4. Automatically translate the new value to all other configured locales using AI
|
|
206
|
-
5. Update all relevant namespace files with the new values
|
|
160
|
+
**Result**: No duplicate keys, instant code.
|
|
207
161
|
|
|
208
|
-
|
|
162
|
+
If nothing exists:
|
|
163
|
+
- AI adds key to English: `add_translation_key`
|
|
164
|
+
- You run: `npx @scoutello/i18n-magic sync`
|
|
165
|
+
- Translated to all languages!
|
|
209
166
|
|
|
210
|
-
|
|
211
|
-
- Using the option flag: `npx @scoutello/i18n-magic replace --key your.translation.key`
|
|
167
|
+
### Pattern 2: Updating Translations
|
|
212
168
|
|
|
213
|
-
|
|
169
|
+
**You**: "Change welcome message to 'Welcome back!'"
|
|
214
170
|
|
|
215
|
-
|
|
171
|
+
**AI**:
|
|
172
|
+
1. Finds the key via search
|
|
173
|
+
2. Calls `update_translation_key`
|
|
174
|
+
3. **Auto-translates to ALL languages instantly**
|
|
216
175
|
|
|
217
|
-
|
|
218
|
-
- Fixing translation errors across all locales
|
|
219
|
-
- Maintaining consistency when modifying content
|
|
220
|
-
- Automatically updating translations in all relevant namespaces
|
|
176
|
+
No sync needed!
|
|
221
177
|
|
|
222
|
-
###
|
|
178
|
+
### Pattern 3: Batch Check
|
|
223
179
|
|
|
224
|
-
|
|
180
|
+
**You**: "What translations are missing?"
|
|
225
181
|
|
|
226
|
-
|
|
182
|
+
**AI**: Calls `list_untranslated_keys`, shows you the list.
|
|
227
183
|
|
|
228
|
-
|
|
229
|
-
2. Check if all found translation keys exist in your translation files
|
|
230
|
-
3. Report any missing translations without prompting for input
|
|
231
|
-
4. Exit with an error code if missing translations are found
|
|
184
|
+
Add them now or during development. Your choice.
|
|
232
185
|
|
|
233
|
-
|
|
186
|
+
---
|
|
234
187
|
|
|
235
|
-
|
|
236
|
-
- Pre-commit hooks to catch missing translations early
|
|
237
|
-
- Quality assurance checks before deployment
|
|
238
|
-
- Automated testing of translation coverage
|
|
188
|
+
## Real Example
|
|
239
189
|
|
|
240
|
-
|
|
190
|
+
Building a UserProfile component:
|
|
241
191
|
|
|
242
|
-
|
|
192
|
+
**You**: "Replace 'User Profile' with translation"
|
|
243
193
|
|
|
244
|
-
|
|
194
|
+
**AI**:
|
|
195
|
+
- Searches for "user profile"
|
|
196
|
+
- Nothing found
|
|
197
|
+
- Adds: `profile.title: "User Profile"` to en/dashboard.json
|
|
198
|
+
- Updates code: `<h1>{t('profile.title')}</h1>`
|
|
245
199
|
|
|
246
|
-
|
|
247
|
-
2. Identify keys that are missing in other locales
|
|
248
|
-
3. Automatically translate missing keys using AI
|
|
249
|
-
4. Update translation files for all non-default locales
|
|
250
|
-
5. Preserve existing translations (only adds missing ones)
|
|
200
|
+
**You**: "Add translations for labels"
|
|
251
201
|
|
|
252
|
-
|
|
202
|
+
**AI**:
|
|
203
|
+
- Searches "email" → finds `emailLabel` in common
|
|
204
|
+
- Reuses existing key (no duplicate!)
|
|
205
|
+
- Searches "full name" → nothing found
|
|
206
|
+
- Adds new: `profile.fullNameLabel: "Full Name"`
|
|
253
207
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
-
|
|
257
|
-
|
|
208
|
+
**You run**:
|
|
209
|
+
```bash
|
|
210
|
+
npx @scoutello/i18n-magic sync
|
|
211
|
+
```
|
|
258
212
|
|
|
259
|
-
**
|
|
213
|
+
**Result**: All keys now in EN, DE, ES, FR. Took 2 minutes.
|
|
260
214
|
|
|
261
|
-
|
|
215
|
+
Later: **"Change title to 'Your Profile'"**
|
|
262
216
|
|
|
263
|
-
|
|
217
|
+
**AI**: Calls `update_translation_key` → instantly updated in all 4 languages. No sync needed!
|
|
264
218
|
|
|
265
|
-
|
|
219
|
+
---
|
|
266
220
|
|
|
267
|
-
|
|
268
|
-
2. Compare found keys with existing translation files
|
|
269
|
-
3. Remove unused keys from all locale files
|
|
270
|
-
4. Report how many keys were removed
|
|
221
|
+
## Pro Tips
|
|
271
222
|
|
|
272
|
-
|
|
223
|
+
### Better Translations with Context
|
|
273
224
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
225
|
+
```javascript
|
|
226
|
+
// Generic → Okay
|
|
227
|
+
context: 'Web application'
|
|
277
228
|
|
|
278
|
-
|
|
229
|
+
// Specific → Much better!
|
|
230
|
+
context: 'E-commerce for outdoor gear. Friendly tone. Target: adventurers.'
|
|
231
|
+
```
|
|
279
232
|
|
|
280
|
-
|
|
233
|
+
More context = better AI translations.
|
|
281
234
|
|
|
282
|
-
###
|
|
235
|
+
### CI/CD: Auto-translate on PR
|
|
283
236
|
|
|
284
|
-
|
|
237
|
+
```yaml
|
|
238
|
+
# .github/workflows/auto-translate.yml
|
|
239
|
+
on:
|
|
240
|
+
pull_request:
|
|
241
|
+
paths: ['locales/en/**/*.json']
|
|
285
242
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
243
|
+
jobs:
|
|
244
|
+
translate:
|
|
245
|
+
steps:
|
|
246
|
+
- run: npx @scoutello/i18n-magic sync
|
|
247
|
+
- run: git commit -am "chore: auto-translate"
|
|
290
248
|
```
|
|
291
249
|
|
|
292
|
-
|
|
250
|
+
English changes → auto-translated → committed. Zero manual work.
|
|
293
251
|
|
|
294
|
-
|
|
252
|
+
### Namespace Strategy
|
|
295
253
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
254
|
+
- **<100 keys**: Single `common.json`
|
|
255
|
+
- **100-500 keys**: Split by feature (`auth`, `dashboard`)
|
|
256
|
+
- **500+ keys**: Feature-based with auto-assignment (see setup section)
|
|
257
|
+
|
|
258
|
+
### Custom Storage Solutions
|
|
259
|
+
|
|
260
|
+
Store translations anywhere (S3, databases, CDNs):
|
|
261
|
+
|
|
262
|
+
```javascript
|
|
263
|
+
// Example: S3 storage
|
|
264
|
+
const { S3Client, GetObjectCommand, PutObjectCommand } = require('@aws-sdk/client-s3')
|
|
265
|
+
|
|
266
|
+
const s3Client = new S3Client({
|
|
267
|
+
region: process.env.S3_REGION,
|
|
268
|
+
credentials: {
|
|
269
|
+
accessKeyId: process.env.S3_ACCESS_KEY,
|
|
270
|
+
secretAccessKey: process.env.S3_SECRET_KEY,
|
|
302
271
|
}
|
|
272
|
+
})
|
|
273
|
+
|
|
274
|
+
module.exports = {
|
|
275
|
+
loadPath: async (locale, namespace) => {
|
|
276
|
+
const response = await s3Client.send(
|
|
277
|
+
new GetObjectCommand({
|
|
278
|
+
Bucket: 'my-translations-bucket',
|
|
279
|
+
Key: `locales/${locale}/${namespace}.json`,
|
|
280
|
+
})
|
|
281
|
+
)
|
|
282
|
+
const data = await response.Body.transformToString()
|
|
283
|
+
return JSON.parse(data)
|
|
284
|
+
},
|
|
285
|
+
|
|
286
|
+
savePath: async (locale, namespace, data) => {
|
|
287
|
+
await s3Client.send(
|
|
288
|
+
new PutObjectCommand({
|
|
289
|
+
Bucket: 'my-translations-bucket',
|
|
290
|
+
Key: `locales/${locale}/${namespace}.json`,
|
|
291
|
+
Body: JSON.stringify(data, null, 2),
|
|
292
|
+
ContentType: 'application/json',
|
|
293
|
+
})
|
|
294
|
+
)
|
|
295
|
+
},
|
|
296
|
+
// ... other config
|
|
303
297
|
}
|
|
304
298
|
```
|
|
305
299
|
|
|
306
|
-
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Troubleshooting
|
|
303
|
+
|
|
304
|
+
### MCP Connection Error
|
|
305
|
+
|
|
306
|
+
**Error**: `MCP error -32000: Connection closed`
|
|
307
|
+
|
|
308
|
+
**Fix**: Use auto-detection (no `cwd` needed):
|
|
307
309
|
```json
|
|
308
310
|
{
|
|
309
311
|
"i18n-magic": {
|
|
310
312
|
"command": "node",
|
|
311
|
-
"args": ["./node_modules/@scoutello/i18n-magic/dist/mcp-server.js"]
|
|
312
|
-
"cwd": "/absolute/path/to/your/project"
|
|
313
|
+
"args": ["./node_modules/@scoutello/i18n-magic/dist/mcp-server.js"]
|
|
313
314
|
}
|
|
314
315
|
}
|
|
315
316
|
```
|
|
316
317
|
|
|
317
|
-
|
|
318
|
-
- Replace `/absolute/path/to/your/project` with **YOUR PROJECT DIRECTORY** containing `i18n-magic.js`
|
|
319
|
-
- **DO NOT** use the i18n-magic package directory - use where YOU use translations
|
|
320
|
-
- The `cwd` parameter must be an absolute path
|
|
321
|
-
- If you get "Connection closed" error, verify your `cwd` points to the correct directory
|
|
322
|
-
|
|
323
|
-
### Troubleshooting MCP Setup
|
|
324
|
-
|
|
325
|
-
**Error: "MCP error -32000: Connection closed"**
|
|
326
|
-
|
|
327
|
-
This means the server couldn't find your configuration. Check:
|
|
328
|
-
|
|
329
|
-
1. ✅ `cwd` points to YOUR project directory (not the i18n-magic package)
|
|
330
|
-
2. ✅ `i18n-magic.js` exists in that directory
|
|
331
|
-
3. ✅ Paths are absolute
|
|
332
|
-
|
|
333
|
-
Test your setup:
|
|
318
|
+
**Still broken?** Check `i18n-magic.js` exists in project root:
|
|
334
319
|
```bash
|
|
335
|
-
# Navigate to your project
|
|
336
|
-
cd /your/project/path
|
|
337
|
-
|
|
338
|
-
# Verify config exists
|
|
339
320
|
ls -la i18n-magic.js
|
|
340
|
-
|
|
341
|
-
# Test the MCP server manually
|
|
342
|
-
node ./node_modules/@scoutello/i18n-magic/dist/mcp-server.js
|
|
343
321
|
```
|
|
344
322
|
|
|
345
|
-
|
|
323
|
+
### Translations Not Working
|
|
346
324
|
|
|
347
|
-
|
|
325
|
+
**Problem**: Keys added but not translated.
|
|
326
|
+
|
|
327
|
+
**Fix**: Run sync!
|
|
328
|
+
```bash
|
|
329
|
+
npx @scoutello/i18n-magic sync
|
|
330
|
+
```
|
|
348
331
|
|
|
349
|
-
|
|
350
|
-
1. While coding, the LLM identifies a missing translation key
|
|
351
|
-
2. The LLM calls the `add_translation_key` tool to add it with an English value
|
|
352
|
-
3. The key is automatically added to the `en` locale (regardless of your `defaultLocale`)
|
|
353
|
-
4. Run `i18n-magic sync` to translate the key to all other configured locales
|
|
332
|
+
`add_translation_key` only adds English. `sync` translates to other languages.
|
|
354
333
|
|
|
355
|
-
|
|
356
|
-
1. The LLM calls `list_untranslated_keys` to get a complete overview
|
|
357
|
-
2. Review all missing keys grouped by namespace
|
|
358
|
-
3. Add keys using `add_translation_key` or run `i18n-magic scan` for batch processing
|
|
359
|
-
4. Run `i18n-magic sync` to translate all new keys
|
|
334
|
+
### MCP Tools Not Appearing
|
|
360
335
|
|
|
361
|
-
|
|
336
|
+
1. Restart Cursor after adding MCP config
|
|
337
|
+
2. Check Settings → Features → MCP shows "i18n-magic" as Connected
|
|
338
|
+
3. Test: Ask AI to *"search translations for 'password'"*
|
|
362
339
|
|
|
363
|
-
|
|
340
|
+
---
|
|
364
341
|
|
|
365
|
-
|
|
366
|
-
- `key` (required): The translation key (e.g., "welcomeMessage")
|
|
367
|
-
- `value` (required): The English text value
|
|
368
|
-
- `namespace` (optional): Target namespace (defaults to your defaultNamespace)
|
|
342
|
+
## Get Started Now
|
|
369
343
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
"namespace": "common"
|
|
376
|
-
}
|
|
377
|
-
```
|
|
344
|
+
1. `npm install @scoutello/i18n-magic`
|
|
345
|
+
2. Create `i18n-magic.js` config (see setup section)
|
|
346
|
+
3. Add `OPENAI_API_KEY` to `.env`
|
|
347
|
+
4. Configure MCP in Cursor
|
|
348
|
+
5. Start coding. AI handles translations.
|
|
378
349
|
|
|
379
|
-
**
|
|
350
|
+
**5 minutes to set up. Hours saved every week.**
|
|
380
351
|
|
|
381
|
-
|
|
382
|
-
- `namespace` (optional): Check a specific namespace only (defaults to all namespaces)
|
|
352
|
+
### Links
|
|
383
353
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
354
|
+
- **MCP Details**: [MCP-SERVER.md](./MCP-SERVER.md)
|
|
355
|
+
- **Example App**: [example-app/](./example-app/)
|
|
356
|
+
- **GitHub**: [github.com/BjoernRave/i18n-magic](https://github.com/BjoernRave/i18n-magic)
|
|
357
|
+
- **NPM**: [@scoutello/i18n-magic](https://www.npmjs.com/package/@scoutello/i18n-magic)
|
|
388
358
|
|
|
389
|
-
|
|
359
|
+
---
|
|
390
360
|
|
|
391
|
-
|
|
361
|
+
*Never context switch for translations again. 🌍*
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -59,13 +59,41 @@ export declare class TranslationError extends Error {
|
|
|
59
59
|
constructor(message: string, locale?: string, namespace?: string, cause?: Error);
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
* Add a translation key with
|
|
63
|
-
* This function
|
|
64
|
-
*
|
|
62
|
+
* Add a translation key with a value in a specific language to the locale files.
|
|
63
|
+
* This function adds to the specified language locale, and will also translate
|
|
64
|
+
* and save to other locales if OpenAI is configured.
|
|
65
65
|
*/
|
|
66
|
-
|
|
66
|
+
/**
|
|
67
|
+
* Add multiple translation keys in batch. This is optimized for performance:
|
|
68
|
+
* - Single codebase scan for all keys
|
|
69
|
+
* - Batched file I/O operations
|
|
70
|
+
* - Batched translations per locale
|
|
71
|
+
*/
|
|
72
|
+
export declare const addTranslationKeys: ({ keys, config, }: {
|
|
73
|
+
keys: Array<{
|
|
74
|
+
key: string;
|
|
75
|
+
value: string;
|
|
76
|
+
language?: string;
|
|
77
|
+
}>;
|
|
78
|
+
config: Configuration;
|
|
79
|
+
}) => Promise<{
|
|
80
|
+
results: {
|
|
81
|
+
key: string;
|
|
82
|
+
value: string;
|
|
83
|
+
namespace: string;
|
|
84
|
+
locale: string;
|
|
85
|
+
}[];
|
|
86
|
+
performance: {
|
|
87
|
+
totalTime: number;
|
|
88
|
+
scanTime: number;
|
|
89
|
+
translationTime: number;
|
|
90
|
+
fileIOTime: number;
|
|
91
|
+
};
|
|
92
|
+
}>;
|
|
93
|
+
export declare const addTranslationKey: ({ key, value, language, config, }: {
|
|
67
94
|
key: string;
|
|
68
95
|
value: string;
|
|
96
|
+
language?: string;
|
|
69
97
|
config: Configuration;
|
|
70
98
|
}) => Promise<{
|
|
71
99
|
key: string;
|