@camscanner/mcp-language-server 1.1.0 → 1.2.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/dist/index.js CHANGED
@@ -335,20 +335,54 @@ server.tool('write-locales', '搜索多语言字符串并直接写入项目的 l
335
335
  results.push(`${localeName}.json: 无变化 (${Object.keys(newEntries).length} 条已存在)`);
336
336
  }
337
337
  }
338
- // Detect local locale files that got no remote data
338
+ // Fallback: local locale files with no remote translation use English (langId=2)
339
+ const englishEntries = allStrings['2'] || {};
339
340
  const localLocaleNames = fs_1.default.readdirSync(locales_path)
340
341
  .filter(f => f.endsWith('.json'))
341
342
  .map(f => f.replace('.json', ''));
342
343
  const missingLocales = (0, utils_js_1.findMissingLocales)(localLocaleNames, Object.keys(allStrings));
344
+ let fallbackCount = 0;
345
+ if (Object.keys(englishEntries).length > 0) {
346
+ for (const localeName of missingLocales) {
347
+ const filePath = path_1.default.join(locales_path, `${localeName}.json`);
348
+ if (!fs_1.default.existsSync(filePath))
349
+ continue;
350
+ let existingObj = {};
351
+ try {
352
+ const content = fs_1.default.readFileSync(filePath, 'utf-8');
353
+ existingObj = JSON.parse(content);
354
+ }
355
+ catch {
356
+ // empty or invalid file
357
+ }
358
+ const { merged, keysAdded, keysUpdated } = (0, utils_js_1.mergeLocaleEntries)(existingObj, englishEntries);
359
+ fs_1.default.writeFileSync(filePath, JSON.stringify(merged, null, 2) + '\n');
360
+ filesWritten++;
361
+ fallbackCount++;
362
+ totalKeys += Object.keys(englishEntries).length;
363
+ if (keysAdded.length > 0 || keysUpdated.length > 0) {
364
+ results.push(`${localeName}.json: +${keysAdded.length} 新增, ~${keysUpdated.length} 更新 (英语兜底)`);
365
+ }
366
+ else {
367
+ results.push(`${localeName}.json: 无变化 (${Object.keys(englishEntries).length} 条已存在)`);
368
+ }
369
+ }
370
+ }
371
+ // Remaining missing locales (no English fallback available)
372
+ const stillMissing = Object.keys(englishEntries).length > 0
373
+ ? [] // all missing locales got English fallback
374
+ : missingLocales;
343
375
  let output = `写入完成!\n`;
344
376
  output += `- 目录: ${locales_path}\n`;
345
377
  output += `- 写入 ${filesWritten} 个文件, 跳过 ${filesSkipped} 个 (项目中不存在)\n`;
378
+ if (fallbackCount > 0) {
379
+ output += `- 其中 ${fallbackCount} 个文件使用英语兜底\n`;
380
+ }
346
381
  output += `- 共 ${totalKeys} 条字符串\n\n`;
347
382
  output += results.map(r => ` ${r}`).join('\n');
348
- if (missingLocales.length > 0) {
349
- output += `\n\n⚠️ 以下 ${missingLocales.length} 个本地语言文件未获得远程翻译,未被更新:\n`;
350
- output += missingLocales.map(name => ` - ${name}.json`).join('\n');
351
- output += `\n请确认远程平台是否已为这些语言提供翻译。`;
383
+ if (stillMissing.length > 0) {
384
+ output += `\n\n⚠️ 以下 ${stillMissing.length} 个本地语言文件未获得远程翻译,且无英语兜底:\n`;
385
+ output += stillMissing.map(name => ` - ${name}.json`).join('\n');
352
386
  }
353
387
  return { content: [{ type: 'text', text: output }] };
354
388
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camscanner/mcp-language-server",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "MCP Server for multi-language string management",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/index.ts CHANGED
@@ -414,22 +414,58 @@ server.tool(
414
414
  }
415
415
  }
416
416
 
417
- // Detect local locale files that got no remote data
417
+ // Fallback: local locale files with no remote translation use English (langId=2)
418
+ const englishEntries = allStrings['2'] || {}
418
419
  const localLocaleNames = fs.readdirSync(locales_path)
419
420
  .filter(f => f.endsWith('.json'))
420
421
  .map(f => f.replace('.json', ''))
421
422
  const missingLocales = findMissingLocales(localLocaleNames, Object.keys(allStrings))
423
+ let fallbackCount = 0
424
+
425
+ if (Object.keys(englishEntries).length > 0) {
426
+ for (const localeName of missingLocales) {
427
+ const filePath = path.join(locales_path, `${localeName}.json`)
428
+ if (!fs.existsSync(filePath)) continue
429
+
430
+ let existingObj: Record<string, string> = {}
431
+ try {
432
+ const content = fs.readFileSync(filePath, 'utf-8')
433
+ existingObj = JSON.parse(content)
434
+ } catch {
435
+ // empty or invalid file
436
+ }
437
+
438
+ const { merged, keysAdded, keysUpdated } = mergeLocaleEntries(existingObj, englishEntries)
439
+
440
+ fs.writeFileSync(filePath, JSON.stringify(merged, null, 2) + '\n')
441
+ filesWritten++
442
+ fallbackCount++
443
+ totalKeys += Object.keys(englishEntries).length
444
+ if (keysAdded.length > 0 || keysUpdated.length > 0) {
445
+ results.push(`${localeName}.json: +${keysAdded.length} 新增, ~${keysUpdated.length} 更新 (英语兜底)`)
446
+ } else {
447
+ results.push(`${localeName}.json: 无变化 (${Object.keys(englishEntries).length} 条已存在)`)
448
+ }
449
+ }
450
+ }
451
+
452
+ // Remaining missing locales (no English fallback available)
453
+ const stillMissing = Object.keys(englishEntries).length > 0
454
+ ? [] // all missing locales got English fallback
455
+ : missingLocales
422
456
 
423
457
  let output = `写入完成!\n`
424
458
  output += `- 目录: ${locales_path}\n`
425
459
  output += `- 写入 ${filesWritten} 个文件, 跳过 ${filesSkipped} 个 (项目中不存在)\n`
460
+ if (fallbackCount > 0) {
461
+ output += `- 其中 ${fallbackCount} 个文件使用英语兜底\n`
462
+ }
426
463
  output += `- 共 ${totalKeys} 条字符串\n\n`
427
464
  output += results.map(r => ` ${r}`).join('\n')
428
465
 
429
- if (missingLocales.length > 0) {
430
- output += `\n\n⚠️ 以下 ${missingLocales.length} 个本地语言文件未获得远程翻译,未被更新:\n`
431
- output += missingLocales.map(name => ` - ${name}.json`).join('\n')
432
- output += `\n请确认远程平台是否已为这些语言提供翻译。`
466
+ if (stillMissing.length > 0) {
467
+ output += `\n\n⚠️ 以下 ${stillMissing.length} 个本地语言文件未获得远程翻译,且无英语兜底:\n`
468
+ output += stillMissing.map(name => ` - ${name}.json`).join('\n')
433
469
  }
434
470
 
435
471
  return { content: [{ type: 'text', text: output }] }