final_cleanup.js 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. const fs = require('fs');
  2. const path = require('path');
  3. const translationsPath = path.join('d:', 'workspace', 'AuraK', 'web', 'utils', 'translations.ts');
  4. const betterTranslations = {
  5. navAgent: { zh: "智能体", en: "Agent", ja: "エージェント" },
  6. navNotebook: { zh: "笔记本", en: "Notebook", ja: "ノートブック" },
  7. navPlugin: { zh: "插件", en: "Plugins", ja: "プラグイン" },
  8. navTenants: { zh: "租户管理", en: "Tenants", ja: "テナント管理" },
  9. noNotesFound: { zh: "未找到笔记", en: "No notes found", ja: "ノートが見つかりません" },
  10. notebookDesc: { zh: "笔记本功能可以帮助您整理和归纳知识。", en: "Notebooks help you organize and summarize knowledge.", ja: "ノートブックは知識の整理と要約に役立ちます。" },
  11. personalNotebook: { zh: "个人笔记本", en: "Personal Notebook", ja: "個人用ノートブック" },
  12. pluginBy: { zh: "作者", en: "By", ja: "作者" },
  13. pluginCommunity: { zh: "社区插件", en: "Community Plugins", ja: "コミュニティプラグイン" },
  14. pluginConfig: { zh: "插件配置", en: "Plugin Config", ja: "プラグイン設定" },
  15. pluginDesc: { zh: "扩展系统功能。", en: "Extend system capabilities.", ja: "システム機能を拡張します。" },
  16. pluginOfficial: { zh: "官方插件", en: "Official Plugins", ja: "公式プラグイン" },
  17. pluginTitle: { zh: "插件", en: "Plugins", ja: "プラグイン" },
  18. searchAgent: { zh: "搜索智能体", en: "Search Agents", ja: "エージェントを検索" },
  19. searchPlugin: { zh: "搜索插件", en: "Search Plugins", ja: "プラグインを検索" },
  20. statusRunning: { zh: "运行中", en: "Running", ja: "実行中" },
  21. statusStopped: { zh: "已停止", en: "Stopped", ja: "停止中" },
  22. success: { zh: "成功", en: "Success", ja: "成功" },
  23. updatedAtPrefix: { zh: "最后更新于", en: "Last updated at", ja: "最終更新日:" },
  24. visualVision: { zh: "视觉分析", en: "Visual Analysis", ja: "視覚分析" },
  25. warning: { zh: "警告", en: "Warning", ja: "警告" },
  26. "x-api-key": { zh: "API 密钥", en: "API Key", ja: "APIキー" },
  27. "x-tenant-id": { zh: "租户 ID", en: "Tenant ID", ja: "テナントID" },
  28. "x-user-language": { zh: "用户语言", en: "User Language", ja: "ユーザー言語" },
  29. unknown: { zh: "未知", en: "Unknown", ja: "不明" }
  30. };
  31. let content = fs.readFileSync(translationsPath, 'utf8');
  32. function isValidIdentifier(id) {
  33. return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(id);
  34. }
  35. // Simple parser to extract blocks
  36. const langBlocks = content.split(/(\w+): \{/);
  37. let header = langBlocks[0];
  38. let newContent = header;
  39. for (let i = 1; i < langBlocks.length; i += 2) {
  40. const lang = langBlocks[i];
  41. let block = langBlocks[i + 1];
  42. // Find the end of this block
  43. let endIdx = block.lastIndexOf('},');
  44. if (endIdx === -1) endIdx = block.lastIndexOf('}'); // last block
  45. let footer = block.substring(endIdx);
  46. let itemsStr = block.substring(0, endIdx);
  47. let items = itemsStr.split('\n');
  48. let seenKeys = new Set();
  49. let resultItems = [];
  50. for (let line of items) {
  51. let match = line.match(/^(\s+)(['"]?[a-zA-Z0-9_-]+['"]?):(.*)/);
  52. if (match) {
  53. let indent = match[1];
  54. let keyStr = match[2];
  55. let rest = match[3];
  56. let actualKey = keyStr.replace(/['"]/g, '');
  57. if (seenKeys.has(actualKey)) continue;
  58. seenKeys.add(actualKey);
  59. let val = rest.trim().replace(/,$/, '');
  60. // If it's a placeholder (same as key) or empty, use better translation if available
  61. if ((val === `"${actualKey}"` || val === `'${actualKey}'`) && betterTranslations[actualKey]) {
  62. val = JSON.stringify(betterTranslations[actualKey][lang] || betterTranslations[actualKey].en || actualKey);
  63. }
  64. const quotedKey = isValidIdentifier(actualKey) ? actualKey : `"${actualKey}"`;
  65. resultItems.push(`${indent}${quotedKey}: ${val},`);
  66. } else if (line.trim().startsWith('//') || line.trim() === '') {
  67. resultItems.push(line);
  68. }
  69. }
  70. newContent += `${lang}: {` + resultItems.join('\n') + footer;
  71. }
  72. fs.writeFileSync(translationsPath, newContent, 'utf8');
  73. console.log('Final cleanup and translation improvement complete!');