From 2cc7513aa2cbca484007a594e2aa378e02bb769e Mon Sep 17 00:00:00 2001 From: roberttwang Date: Fri, 27 Nov 2026 19:48:45 +0000 Subject: [PATCH 1/3] =?UTF-8?q?fix(web):=20=E8=83=BD=E5=8A=9B=E8=B5=84?= =?UTF-8?q?=E4=BA=A7=E4=B8=8E=E6=B2=99=E7=AE=B1=E9=A1=B5=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E7=95=8C=E9=9D=A2=E4=B8=8D=E5=86=8D=E6=94=B9=E5=86=99=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=91=BD=E5=90=8D=E7=9A=84=E8=B5=84=E4=BA=A7=E5=90=8D?= =?UTF-8?q?=EF=BC=8C=E8=A1=A5=E9=BD=90=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In English mode the runtime dictionary rewrote words inside names and descriptions people typed on the rules, skills, sandboxes and MCP pages whenever a dictionary word sat next to a space or ASCII text: the sandbox "走查 native 沙箱" showed as "走查 native Sandboxes", the MCP "GitHub 知识库" as "GitHub Knowledge", "检索 GitHub 项目 文档" as "Search GitHub Projects 文档", and the personal MCP hint turned the user "E2E 本地" into "E2E Local". The rest of these pages stayed Chinese or mixed ("未共享", "10 个流程引用", "添加到"全量走查项目", They won't appear in other projects."). - assets.js / mcp.js mark asset, MCP, project, user and LOOP/role names and descriptions as data-i18n-data, so English mode only takes whole-string dictionary hits for them (built-in names still translate). - Card aria-labels, reference counts, the Dockerfile line count, the list count line, the empty-search state, delete-blocked reasons, the delete and leave confirmations and the MCP scope hints are built with lfT, so English is a whole sentence with the name quoted as typed. - i18n.js: data-i18n-data-attrs="aria-label" marks only the listed attributes as user data, for an element whose own copy must still be translated (the asset card). - afConfirm({messageData:true}) marks a confirmation message that quotes a name as user data and clears the mark for the next dialog. - The field help aria-label no longer doubles 说明 ("工具链说明说明"). - i18n-en.js gains the static copy of these pages (search, scope labels, detail form, sandbox fields and help, MCP hints). - webtest: i18n-assets.test.mjs renders every state of the four pages in an English page and checks names stay as typed and no product copy is left in Chinese. Co-Authored-By: Claude Code --- web/app.js | 5 +- web/app/assets.js | 39 +++--- web/app/mcp.js | 5 +- web/assets_detail_test.js | 4 +- web/i18n-en.js | 75 ++++++++++++ web/i18n.js | 6 +- webtest/tests/i18n-assets.test.mjs | 190 +++++++++++++++++++++++++++++ 7 files changed, 300 insertions(+), 24 deletions(-) create mode 100644 webtest/tests/i18n-assets.test.mjs diff --git a/web/app.js b/web/app.js index 9498b27f0..4e6f1e17e 100644 --- a/web/app.js +++ b/web/app.js @@ -280,7 +280,10 @@ function afConfirm(options){ return afOpenDialog(()=>{ const danger=!!opt.danger; $('#confirmTitle').textContent=opt.title||(danger?'危险操作确认':'操作确认'); - $('#confirmMessage').textContent=opt.message||'确定要继续吗?'; + // messageData: the message quotes user data (a name), so English mode only takes whole-message dictionary hits. + const message=$('#confirmMessage'); + if(opt.messageData)message.setAttribute('data-i18n-data','');else message.removeAttribute('data-i18n-data'); + message.textContent=opt.message||'确定要继续吗?'; const okBtn=$('#confirmOkBtn'); okBtn.textContent=opt.confirmText||(danger?'确定执行':'确定'); okBtn.className=`button ${danger?'danger-btn':'primary'}`; diff --git a/web/app/assets.js b/web/app/assets.js index c619de30b..3b69e390b 100644 --- a/web/app/assets.js +++ b/web/app/assets.js @@ -20,7 +20,7 @@ function assetFindVisible(id){if(!id)return null;const owned=assetScopeItems('pr function assetProjectName(a){return (state.data.projects||[]).find(p=>p.id===a?.projectId)?.name||a?.projectId||'平台'} function assetIsBuiltin(a,type=state.assetType){return type==='sandboxes'&&a?.id==='generic-docker'} function assetStatusHTML(a){ - if(!catalogOwned(a.projectId))return `来自 ${escapeHTML(assetProjectName(a))}`; + if(!catalogOwned(a.projectId))return `来自 ${escapeHTML(assetProjectName(a))}`; return `${a.shared?'已共享':'未共享'}`; } function assetMetaHTML(a){ @@ -33,19 +33,20 @@ function assetMetaHTML(a){ } if(state.assetType==='sandboxes'){ const driver=sandboxDriverOption(a.driver);meta.push(item('server',sandboxDriverLabel(driver))); - if(driver==='docker'&&a.dockerfile?.content)meta.push(item('layers',`Dockerfile ${a.dockerfile.content.trimEnd().split('\n').length} 行`)); + if(driver==='docker'&&a.dockerfile?.content){const lines=a.dockerfile.content.trimEnd().split('\n').length;meta.push(item('layers',lfT(`Dockerfile ${lines} 行`,`Dockerfile · ${lines} ${lines===1?'line':'lines'}`)))} } const refs=assetReferenceNames(a).length; - meta.push(item(assetRefIconName(),refs?`${refs} 个${assetRefKindLabel()}引用`:'未被引用')); + meta.push(item(assetRefIconName(),refs?lfT(`${refs} 个${assetRefKindLabel()}引用`,`Used by ${refs} ${assetRefKindLabelEn(refs)}`):'未被引用')); return meta.join(''); } function assetCardHTML(a){ const readonly=!catalogOwned(a.projectId);const go=readonly?'查看':'编辑'; - return `
${huiIcon(assetIconName())}

${escapeHTML(a.name||a.id)}

${escapeHTML(a.id)}

${escapeHTML(a.description||'暂无说明')}

${assetMetaHTML(a)}
${assetStatusHTML(a)}${go}${huiIcon('chevron-right')}
`; + const name=a.name||a.id,label=lfT(`${go}${assetKindLabel()}「${name}」`,`${readonly?'View':'Edit'} ${assetKindLabelEn()} "${name}"`); + return `
${huiIcon(assetIconName())}

${escapeHTML(name)}

${escapeHTML(a.id)}

${escapeHTML(a.description||'暂无说明')}

${assetMetaHTML(a)}
${assetStatusHTML(a)}${go}${huiIcon('chevron-right')}
`; } function assetGridEmptyHTML(){ const kind=assetKindLabel(),copy=assetPageCopy(); - if(String(state.assetQuery||'').trim())return `
没有匹配「${escapeHTML(state.assetQuery.trim())}」的${escapeHTML(kind)}

换个关键词试试。

`; + if(String(state.assetQuery||'').trim())return `
${escapeHTML(lfT(`没有匹配「${state.assetQuery.trim()}」的${kind}`,`No ${assetKindLabelEn()} matches "${state.assetQuery.trim()}"`))}

换个关键词试试。

`; if(state[assetScopeKey(state.assetType)]==='shared'){const hint=['rules','skills'].includes(state.assetType)?'请在资产所属项目中共享,或共享一个引用它的角色。':'请在沙箱所属项目中共享。';return `
其他项目还没有共享${escapeHTML(kind)}

${hint}

`} return `
当前项目还没有${/^[A-Za-z]/.test(kind)?' ':''}${escapeHTML(kind)}

${assetEmptyHint()}

`; } @@ -53,7 +54,7 @@ function renderAssetGrid(){ const list=$('#assetList');if(!list)return; const scope=state[assetScopeKey(state.assetType)]; const items=assetFilteredItems(); - const count=$('#assetCount');if(count)count.innerHTML=`${scope==='shared'?'共享':'本项目'}${escapeHTML(assetKindLabel())}${items.length}`; + const count=$('#assetCount');if(count)count.innerHTML=`${escapeHTML(lfT(`${scope==='shared'?'共享':'本项目'}${assetKindLabel()}`,scope==='shared'?`Shared ${assetKindLabelEn()}s`:`${assetKindLabelEn().replace(/^./,c=>c.toUpperCase())}s in this project`))}${items.length}`; list.innerHTML=items.map(assetCardHTML).join('')||assetGridEmptyHTML(); const emptyAction=list.querySelector('[data-empty-new]'); if($('#newAsset'))$('#newAsset').hidden=scope!=='project'||!!emptyAction; @@ -100,7 +101,7 @@ function assetCurrent(){ } function assetDetailHeadHTML(a,{creating=false,dirty=false}={}){ const kind=assetKindLabel(),copy=assetPageCopy(),readonly=!creating&&!catalogOwned(a.projectId); - const badge=creating?'':readonly?`来自 ${escapeHTML(assetProjectName(a))}`:`${a.shared?'已共享':'未共享'}`; + const badge=creating?'':readonly?`来自 ${escapeHTML(assetProjectName(a))}`:`${a.shared?'已共享':'未共享'}`; const title=creating?`新建${kind}`:(a.name||a.id); const desc=creating?`填写标识和名称后创建${state.assetType==='skills'?',创建后即可上传文件':''}。`:(a.description||'暂无说明'); let actions; @@ -111,15 +112,15 @@ function assetDetailHeadHTML(a,{creating=false,dirty=false}={}){ actions=`未保存`+ ``+ `
`+ - `
`+ + ``+ ``; } - return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; + return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; } function renderAssetDetailHead(a){ const creating=state.selectedAsset==='__new__',copy=assetPageCopy(); const crumbs=$('#assetCrumbs'); - if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; + if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; const head=$('#assetDetailHead');if(!head)return; closeAssetMenu(); head.innerHTML=assetDetailHeadHTML(a,{creating,dirty:!!state.assetDirty}); @@ -155,7 +156,7 @@ function updateAssetStuck(){ } function assetRefsCardHTML(a){ const refs=assetReferenceNames(a),kind=assetRefKindLabel(); - return `

被引用${refs.length}

`; + return `

被引用${refs.length}

`; } function assetSkillSource(a){const s=a?.source;return state.assetType==='skills'&&s&&s.provider==='skillhub'?s:null} function assetSkillLatest(src){return typeof skillhubLatestFor==='function'?skillhubLatestFor(src):''} @@ -172,7 +173,7 @@ function assetSkillSourceActionHTML(a){ } function assetOverviewCardHTML(a){ const readonly=!catalogOwned(a.projectId); - return `

概览

归属
${readonly?escapeHTML(assetProjectName(a)):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; + return `

概览

归属
${readonly?escapeHTML(assetProjectName(a)):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; } function bindAssetSourceActions(a){ const card=$('#assetForm [data-asset-overview]');if(!card||!assetSkillSource(a))return; @@ -202,7 +203,7 @@ function scrollAssetTop(){ } async function confirmAssetLeave(){ if(!state.selectedAsset||!state.assetDirty||!isProjectSharedAsset(activeViewName()))return true; - const ok=await afConfirm({title:'未保存的修改',message:`当前${assetKindLabel()}有未保存修改,离开将放弃这些修改。继续?`,confirmText:'放弃并离开',danger:true}); + const ok=await afConfirm({title:'未保存的修改',message:lfT(`当前${assetKindLabel()}有未保存修改,离开将放弃这些修改。继续?`,`This ${assetKindLabelEn()} has unsaved changes. Leaving discards them. Continue?`),confirmText:'放弃并离开',danger:true}); if(ok)state.assetDirty=false; return ok; } @@ -259,7 +260,9 @@ async function toggleAssetShare(id){ } function assetEmptyHint(){return ({rules:'规则是写给 Agent 的行为约束,例如编码规范、禁止事项。建好后在「角色定义」里绑定到角色。',skills:'技能是 Agent 可按需加载的说明和附加文件,例如某个框架的操作手册。建好后在「角色定义」里绑定到角色。',sandboxes:'沙箱决定 LOOP 节点和对话工作区在什么隔离环境里执行:docker 沙箱自带 Dockerfile,native 沙箱使用执行机器上已安装的工具。建好后在流程设置里选用;也可以直接用「共享」里的现成配置。'})[state.assetType]||''} function assetKindLabel(){return ({rules:'规则',skills:'技能',sandboxes:'沙箱'})[state.assetType]||'资产'} +function assetKindLabelEn(){return ({rules:'rule',skills:'skill',sandboxes:'sandbox'})[state.assetType]||'asset'} function assetRefKindLabel(){return ({rules:'角色',skills:'角色',sandboxes:'流程'})[state.assetType]||'引用'} +function assetRefKindLabelEn(n){return n===1?(state.assetType==='sandboxes'?'LOOP':'role'):(state.assetType==='sandboxes'?'LOOPs':'roles')} function assetReferenceNames(a){ if(!a?.id)return []; if(state.assetType==='rules')return (state.data.agents||[]).filter(x=>(x.rules||[]).includes(a.id)).map(x=>x.name||x.id); @@ -270,9 +273,9 @@ function assetReferenceNames(a){ function assetDeleteBlocked(a){ if(!a?.id)return '无法删除'; if(state.assetType==='sandboxes'&&a.id==='generic-docker')return `内置沙箱 ${a.id} 不能删除`; - if(a.shared)return `共享状态的${assetKindLabel()}不能删除,请先取消共享`; + if(a.shared)return lfT(`共享状态的${assetKindLabel()}不能删除,请先取消共享`,`A shared ${assetKindLabelEn()} can't be deleted. Stop sharing it first`); const refs=assetReferenceNames(a); - if(refs.length)return `${assetKindLabel()}仍被 ${refs.length} 个${assetRefKindLabel()}引用(${refs.join('、')}),请先解除引用`; + if(refs.length)return lfT(`${assetKindLabel()}仍被 ${refs.length} 个${assetRefKindLabel()}引用(${refs.join('、')}),请先解除引用`,`This ${assetKindLabelEn()} is still used by ${refs.length} ${assetRefKindLabelEn(refs.length)} (${refs.join(', ')}). Remove those references first`); return ''; } async function deleteAsset(id){ @@ -282,13 +285,13 @@ async function deleteAsset(id){ const blocked=assetDeleteBlocked(item); if(blocked)return toast(blocked); const label=assetKindLabel(); - if(!await afConfirm({title:`删除${label}确认`,message:`确认删除${label}「${item.name}」?此操作不可恢复。`,confirmText:'确认删除',danger:true}))return; + if(!await afConfirm({title:`删除${label}确认`,message:lfT(`确认删除${label}「${item.name}」?此操作不可恢复。`,`Delete ${assetKindLabelEn()} "${item.name}"? This can't be undone.`),messageData:true,confirmText:'确认删除',danger:true}))return; try{ await api(`/api/${state.assetType}?id=${encodeURIComponent(id)}`,{method:'DELETE'}); state.data[state.assetType]=(state.data[state.assetType]||[]).filter(x=>x.id!==id); if(state.selectedAsset===id)await closeAssetDetail({force:true}); else renderAssets(); - toast(`${label}已删除`); + toast(lfT(`${label}已删除`,`${assetKindLabelEn().replace(/^./,c=>c.toUpperCase())} deleted`)); }catch(e){toast(e.message||'删除失败')} } function assetKind(){return assetKindLabel()} @@ -312,7 +315,7 @@ function syncSandboxDriverFields(select){ function resolveAssetSaveIdentity(items,selectedID,requestedID){if(selectedID!=='__new__'){const existing=(items||[]).find(item=>item.id===selectedID);return existing?{id:existing.id,existing,created:false}:{error:'选中的资产已不存在,请刷新后重试'}}if((items||[]).some(item=>item.id===requestedID))return {error:'该标识已存在,请换一个标识,或回到列表打开已有资产修改'};return {id:requestedID,existing:null,created:true}} function assetPaneTabs(type=state.assetType){return ({rules:[['edit','编辑'],['preview','预览']],skills:[['files','文件']],sandboxes:[['setup','配置']]})[type]||[['edit','编辑']]} function assetPaneHint(type=state.assetType){return ({rules:'支持 Markdown',skills:'每次上传都会完整替换现有文件',sandboxes:'隔离方式决定沙箱在哪里、怎样执行'})[type]||''} -function assetFieldLabel(text,help,forId=''){return `
${forId?``:`${escapeHTML(text)}`}${help?``:''}
`} +function assetFieldLabel(text,help,forId=''){return `
${forId?``:`${escapeHTML(text)}`}${help?``:''}
`} function sandboxSetupHTML(a){ const driver=sandboxDriverOption(a.driver); const privilegeHelp=lfT('执行机器须允许特权沙箱。容器内进程可访问宿主机设备,并可能控制执行机器。','The execution machine must allow privileged sandboxes. Processes in the container can access host devices and may take control of the machine.'); diff --git a/web/app/mcp.js b/web/app/mcp.js index a4d0bccf0..b07796f22 100644 --- a/web/app/mcp.js +++ b/web/app/mcp.js @@ -187,11 +187,12 @@ function renderMCPManagement(){ const matchedInstalled=installed.filter(item=>mcpMatchesQuery(item,query)); const installedCount=$('#mcpInstalledCount'); if(installedCount)installedCount.textContent=String(matchedInstalled.length); - hint.innerHTML=personal?`个人 MCP仅 ${escapeHTML(userDisplay(state.currentUser)||'当前用户')} 可见。`:`项目 MCP添加到「${escapeHTML(project?.name||'未选择项目')}」,不会出现在其他项目中。`; + const owner=personal?(userDisplay(state.currentUser)||lfT('当前用户','you')):(project?.name||lfT('未选择项目','no project selected')); + hint.innerHTML=personal?`个人 MCP${escapeHTML(lfT(`仅 ${owner} 可见。`,`Only visible to ${owner}.`))}`:`项目 MCP${escapeHTML(lfT(`添加到「${owner}」,不会出现在其他项目中。`,`Added to "${owner}"; it won't appear in other projects.`))}`; if(personal&&(!state.currentUser||state.currentUser.isGuest)){grid.innerHTML='
登录后才能管理个人 MCP

项目级 MCP 仍可在当前项目中管理。

';return} const pagedMCP=paginateList('mcp',matchedInstalled); const catalog=personal?'':mcpCatalogSuggestionsHTML(installed,query); - const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}

${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); + const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}

${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); grid.innerHTML=catalog+(cards||(query?'
没有匹配的 MCP

换个关键词试试。

':`
当前范围还没有 MCP

点击右上角「添加 MCP」,${personal?'创建个人专属配置':'为本项目接入工具'}。

`)); if(cards)grid.insertAdjacentHTML('beforeend',pagerHTML('mcp',pagedMCP)); bindMCPLogoFallbacks(grid); diff --git a/web/assets_detail_test.js b/web/assets_detail_test.js index 8278ab517..4a320951d 100644 --- a/web/assets_detail_test.js +++ b/web/assets_detail_test.js @@ -74,7 +74,7 @@ const shared = ctx.assetCardHTML(ctx.state.data.rules[1]); assert.ok(shared.includes('已共享'), shared); assert.ok(shared.includes('暂无说明') && shared.includes('未被引用'), shared); const foreign = ctx.assetCardHTML(ctx.state.data.rules[2]); -assert.ok(foreign.includes('来自 平台公共'), foreign); +assert.ok(foreign.includes('来自 平台公共'), foreign); assert.ok(foreign.includes('查看'), foreign); for (const html of [own, shared, foreign]) { assert.ok(!/${blocked?`

${escapeHTML(blocked)}

`:''}`+ ``; } - return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; + return `

${escapeHTML(title)}${badge}

${escapeHTML(desc)}

${actions}
`; } function renderAssetDetailHead(a){ const creating=state.selectedAsset==='__new__',copy=assetPageCopy(); const crumbs=$('#assetCrumbs'); - if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; + if(crumbs)crumbs.innerHTML=`${escapeHTML(copy.crumb||`${copy.page} · ${copy.tab}`)}${huiIcon('chevron-right')}${escapeHTML(creating?`新建${assetKindLabel()}`:(a.name||a.id))}`; const head=$('#assetDetailHead');if(!head)return; closeAssetMenu(); head.innerHTML=assetDetailHeadHTML(a,{creating,dirty:!!state.assetDirty}); @@ -156,7 +164,7 @@ function updateAssetStuck(){ } function assetRefsCardHTML(a){ const refs=assetReferenceNames(a),kind=assetRefKindLabel(); - return `

被引用${refs.length}

    ${refs.length?refs.map(name=>`
  • ${huiIcon(assetRefIconName())}${escapeHTML(name)}
  • `).join(''):`
  • 还没有${kind}引用这个${escapeHTML(assetKindLabel())}
  • `}
`; + return `

被引用${refs.length}

    ${refs.length?refs.map(name=>`
  • ${huiIcon(assetRefIconName())}${escapeHTML(name)}
  • `).join(''):`
  • 还没有${kind}引用这个${escapeHTML(assetKindLabel())}
  • `}
`; } function assetSkillSource(a){const s=a?.source;return state.assetType==='skills'&&s&&s.provider==='skillhub'?s:null} function assetSkillLatest(src){return typeof skillhubLatestFor==='function'?skillhubLatestFor(src):''} @@ -173,7 +181,7 @@ function assetSkillSourceActionHTML(a){ } function assetOverviewCardHTML(a){ const readonly=!catalogOwned(a.projectId); - return `

概览

归属
${readonly?escapeHTML(assetProjectName(a)):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; + return `

概览

归属
${readonly?assetProjectNameHTML(a):'本项目'}
共享
${readonly?'其他项目共享':a.shared?'已共享':'未共享'}
${assetIsBuiltin(a)?'
类型
内置
':''}${assetSkillSourceRowsHTML(a)}
${assetSkillSourceActionHTML(a)}`; } function bindAssetSourceActions(a){ const card=$('#assetForm [data-asset-overview]');if(!card||!assetSkillSource(a))return; @@ -260,7 +268,7 @@ async function toggleAssetShare(id){ } function assetEmptyHint(){return ({rules:'规则是写给 Agent 的行为约束,例如编码规范、禁止事项。建好后在「角色定义」里绑定到角色。',skills:'技能是 Agent 可按需加载的说明和附加文件,例如某个框架的操作手册。建好后在「角色定义」里绑定到角色。',sandboxes:'沙箱决定 LOOP 节点和对话工作区在什么隔离环境里执行:docker 沙箱自带 Dockerfile,native 沙箱使用执行机器上已安装的工具。建好后在流程设置里选用;也可以直接用「共享」里的现成配置。'})[state.assetType]||''} function assetKindLabel(){return ({rules:'规则',skills:'技能',sandboxes:'沙箱'})[state.assetType]||'资产'} -function assetKindLabelEn(){return ({rules:'rule',skills:'skill',sandboxes:'sandbox'})[state.assetType]||'asset'} +function assetKindLabelEn(plural=false){return (plural?{rules:'rules',skills:'skills',sandboxes:'sandboxes'}:{rules:'rule',skills:'skill',sandboxes:'sandbox'})[state.assetType]||(plural?'assets':'asset')} function assetRefKindLabel(){return ({rules:'角色',skills:'角色',sandboxes:'流程'})[state.assetType]||'引用'} function assetRefKindLabelEn(n){return n===1?(state.assetType==='sandboxes'?'LOOP':'role'):(state.assetType==='sandboxes'?'LOOPs':'roles')} function assetReferenceNames(a){ @@ -285,7 +293,7 @@ async function deleteAsset(id){ const blocked=assetDeleteBlocked(item); if(blocked)return toast(blocked); const label=assetKindLabel(); - if(!await afConfirm({title:`删除${label}确认`,message:lfT(`确认删除${label}「${item.name}」?此操作不可恢复。`,`Delete ${assetKindLabelEn()} "${item.name}"? This can't be undone.`),messageData:true,confirmText:'确认删除',danger:true}))return; + if(!await afConfirm({title:lfT(`删除${label}确认`,`Delete ${assetKindLabelEn()}`),message:lfT(`确认删除${label}「${item.name}」?此操作不可恢复。`,`Delete ${assetKindLabelEn()} "${item.name}"? This can't be undone.`),messageData:true,confirmText:'确认删除',danger:true}))return; try{ await api(`/api/${state.assetType}?id=${encodeURIComponent(id)}`,{method:'DELETE'}); state.data[state.assetType]=(state.data[state.assetType]||[]).filter(x=>x.id!==id); diff --git a/web/app/mcp.js b/web/app/mcp.js index b07796f22..c83346394 100644 --- a/web/app/mcp.js +++ b/web/app/mcp.js @@ -192,7 +192,7 @@ function renderMCPManagement(){ if(personal&&(!state.currentUser||state.currentUser.isGuest)){grid.innerHTML='
登录后才能管理个人 MCP

项目级 MCP 仍可在当前项目中管理。

';return} const pagedMCP=paginateList('mcp',matchedInstalled); const catalog=personal?'':mcpCatalogSuggestionsHTML(installed,query); - const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}

${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); + const cards=pagedMCP.items.map(item=>`

${escapeHTML(item.name)}

${personal?'个人专属':escapeHTML(project?.name||item.projectId)}
${item.marketId?'市场':'自定义'}
${escapeHTML(item.description||'暂无说明')}

${item.authType==='github-token'?'GitHub 令牌认证':'自定义认证'}${escapeHTML(item.transport||'http')}
${item.marketId?'':``}
`).join(''); grid.innerHTML=catalog+(cards||(query?'
没有匹配的 MCP

换个关键词试试。

':`
当前范围还没有 MCP

点击右上角「添加 MCP」,${personal?'创建个人专属配置':'为本项目接入工具'}。

`)); if(cards)grid.insertAdjacentHTML('beforeend',pagerHTML('mcp',pagedMCP)); bindMCPLogoFallbacks(grid); diff --git a/web/assets_detail_test.js b/web/assets_detail_test.js index 4a320951d..7ce6055b3 100644 --- a/web/assets_detail_test.js +++ b/web/assets_detail_test.js @@ -74,7 +74,7 @@ const shared = ctx.assetCardHTML(ctx.state.data.rules[1]); assert.ok(shared.includes('已共享'), shared); assert.ok(shared.includes('暂无说明') && shared.includes('未被引用'), shared); const foreign = ctx.assetCardHTML(ctx.state.data.rules[2]); -assert.ok(foreign.includes('来自 平台公共'), foreign); +assert.ok(foreign.includes('来自 平台公共'), foreign); assert.ok(foreign.includes('查看'), foreign); for (const html of [own, shared, foreign]) { assert.ok(!/`:''}`} function sandboxSetupHTML(a){ const driver=sandboxDriverOption(a.driver); diff --git a/web/i18n-en.js b/web/i18n-en.js index 3a7b3445d..bac92346a 100644 --- a/web/i18n-en.js +++ b/web/i18n-en.js @@ -1107,7 +1107,6 @@ Object.assign(window.LF_I18N_EN, { "返回沙箱管理": "Back to sandboxes", "只读 · 可直接在本项目使用": "Read-only · usable in this project as is", "未保存": "Unsaved", - "未保存的修改": "Unsaved changes", "放弃并离开": "Discard and leave", "被引用": "Used by", "归属": "Owner", @@ -1117,7 +1116,6 @@ Object.assign(window.LF_I18N_EN, { "规则内容": "Rule content", "技能内容": "Skill content", "沙箱内容": "Sandbox content", - "支持 Markdown": "Markdown supported", "每次上传都会完整替换现有文件": "Each upload replaces all existing files", "隔离方式决定沙箱在哪里、怎样执行": "The isolation driver decides where and how the sandbox runs", "给规则起个名字": "Name this rule", diff --git a/webtest/tests/i18n-assets.test.mjs b/webtest/tests/i18n-assets.test.mjs index f5208352c..e4360ffc4 100644 --- a/webtest/tests/i18n-assets.test.mjs +++ b/webtest/tests/i18n-assets.test.mjs @@ -187,6 +187,29 @@ test('afConfirm marks a message that quotes user data, and clears the mark for t assert.equal(msg().hasAttribute('data-i18n-data'), false); app.document.querySelector('#confirmCancelBtn').click(); await second; + // afPrompt / afAlert write the shared message node without going through afConfirm. + for (const open of [`afPrompt({message:'粘贴内容包含 2 个 server'},'')`, `afAlert({message:'粘贴内容包含 2 个 server'})`]) { + const marked = app.evaluate(`afConfirm({message:'确认删除规则「规则」?',messageData:true})`); + await settle(2); + app.document.querySelector('#confirmCancelBtn').click(); + await marked; + const next = app.evaluate(open); + await settle(2); + assert.equal(msg().hasAttribute('data-i18n-data'), false, `${open} is translated normally after a messageData confirm`); + app.document.querySelector('#confirmCancelBtn').hidden ? app.document.querySelector('#confirmOkBtn').click() : app.document.querySelector('#confirmCancelBtn').click(); + await next; + } +}); + +// Keys of 6+ characters are replaced inside any sentence, so this PR must not add +// ones that other pages embed in longer copy without a whole-sentence entry. +test('asset copy adds no dictionary fragments that split other pages\' sentences', async (t) => { + const en = await englishPage(); + t.after(() => en.close()); + for (const zh of ['放弃未保存的修改?', '已放弃未保存的修改', '跳过会放弃本步骤未保存的修改。', '支持 Markdown 和粘贴图片']) { + const out = en.lfTranslate(zh); + assert.ok(out === zh || !HAN.test(out), `${zh} -> ${out}`); + } }); // A name or description that is itself a dictionary key («沙箱», «代码审查»)