Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,9 @@ function afNextDialog(){
if(rerunFields)rerunFields.hidden=true;
const okBtn=$('#confirmOkBtn'),cancelBtn=$('#confirmCancelBtn');
cancelBtn.hidden=false;
// afConfirm({messageData}) marks the shared message node for one dialog; clear it first so afPrompt,
// afAlert and other setups that write #confirmMessage directly translate normally.
$('#confirmMessage')?.removeAttribute('data-i18n-data');
let opened;
try{opened=job.setup(modal)||{}}catch(err){job.resolve(null);console.error(err);return afNextDialog()}
window.HuiPopover?.closeAll?.();
Expand Down Expand Up @@ -280,7 +283,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','');
message.textContent=opt.message||'确定要继续吗?';
const okBtn=$('#confirmOkBtn');
okBtn.textContent=opt.confirmText||(danger?'确定执行':'确定');
okBtn.className=`button ${danger?'danger-btn':'primary'}`;
Expand Down
51 changes: 31 additions & 20 deletions web/app/assets.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions web/app/mcp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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?`<b>个人 MCP</b><span>仅 ${escapeHTML(userDisplay(state.currentUser)||'当前用户')} 可见。</span>`:`<b>项目 MCP</b><span>添加到「${escapeHTML(project?.name||'未选择项目')}」,不会出现在其他项目中。</span>`;
const owner=personal?(userDisplay(state.currentUser)||lfT('当前用户','you')):(project?.name||lfT('未选择项目','no project selected'));
hint.innerHTML=personal?`<b>个人 MCP</b><span data-i18n-data>${escapeHTML(lfT(`仅 ${owner} 可见。`,`Only visible to ${owner}.`))}</span>`:`<b>项目 MCP</b><span data-i18n-data>${escapeHTML(lfT(`添加到「${owner}」,不会出现在其他项目中。`,`Added to "${owner}"; it won't appear in other projects.`))}</span>`;
if(personal&&(!state.currentUser||state.currentUser.isGuest)){grid.innerHTML='<div class="mcp-market-empty"><b>登录后才能管理个人 MCP</b><p>项目级 MCP 仍可在当前项目中管理。</p></div>';return}
const pagedMCP=paginateList('mcp',matchedInstalled);
const catalog=personal?'':mcpCatalogSuggestionsHTML(installed,query);
const cards=pagedMCP.items.map(item=>`<article class="mcp-market-card is-installed"><div class="mcp-card-head"><span class="mcp-card-logo">${mcpMarketLogo(item)}</span><div><h3>${escapeHTML(item.name)}</h3><small>${personal?'个人专属':escapeHTML(project?.name||item.projectId)}</small></div><span class="mcp-installed-badge ${item.marketId?'is-market':'is-custom'}">${item.marketId?'市场':'自定义'}</span></div><p>${escapeHTML(item.description||'暂无说明')}</p><div class="mcp-card-meta">${item.authType==='github-token'?'<span>GitHub 令牌认证</span>':'<span>自定义认证</span>'}<span>${escapeHTML(item.transport||'http')}</span></div><div class="mcp-card-actions"><div class="mcp-action-buttons">${item.marketId?'':`<button class="button ghost small" type="button" data-mcp-edit="${escapeHTML(item.id)}">修改</button>`}<button class="button ghost small danger" type="button" data-mcp-remove="${escapeHTML(item.id)}">移除</button></div></div></article>`).join('');
const cards=pagedMCP.items.map(item=>`<article class="mcp-market-card is-installed"><div class="mcp-card-head"><span class="mcp-card-logo">${mcpMarketLogo(item)}</span><div><h3 data-i18n-skip>${escapeHTML(item.name)}</h3><small${personal?'':' data-i18n-skip'}>${personal?'个人专属':escapeHTML(project?.name||item.projectId)}</small></div><span class="mcp-installed-badge ${item.marketId?'is-market':'is-custom'}">${item.marketId?'市场':'自定义'}</span></div><p${item.description?' data-i18n-skip':''}>${escapeHTML(item.description||'暂无说明')}</p><div class="mcp-card-meta">${item.authType==='github-token'?'<span>GitHub 令牌认证</span>':'<span>自定义认证</span>'}<span>${escapeHTML(item.transport||'http')}</span></div><div class="mcp-card-actions"><div class="mcp-action-buttons">${item.marketId?'':`<button class="button ghost small" type="button" data-mcp-edit="${escapeHTML(item.id)}">修改</button>`}<button class="button ghost small danger" type="button" data-mcp-remove="${escapeHTML(item.id)}">移除</button></div></div></article>`).join('');
grid.innerHTML=catalog+(cards||(query?'<div class="mcp-market-empty"><b>没有匹配的 MCP</b><p>换个关键词试试。</p></div>':`<div class="mcp-market-empty"><b>当前范围还没有 MCP</b><p>点击右上角「添加 MCP」,${personal?'创建个人专属配置':'为本项目接入工具'}。</p></div>`));
if(cards)grid.insertAdjacentHTML('beforeend',pagerHTML('mcp',pagedMCP));
bindMCPLogoFallbacks(grid);
Expand Down
4 changes: 2 additions & 2 deletions web/assets_detail_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const shared = ctx.assetCardHTML(ctx.state.data.rules[1]);
assert.ok(shared.includes('<span class="asset-status is-on"><i></i>已共享</span>'), shared);
assert.ok(shared.includes('暂无说明') && shared.includes('未被引用'), shared);
const foreign = ctx.assetCardHTML(ctx.state.data.rules[2]);
assert.ok(foreign.includes('<span class="asset-status is-from"><i></i>来自 平台公共</span>'), foreign);
assert.ok(foreign.includes('<span class="asset-status is-from"><i></i>来自 <span data-i18n-skip>平台公共</span></span>'), foreign);
assert.ok(foreign.includes('查看<i data-icon="chevron-right">'), foreign);
for (const html of [own, shared, foreign]) {
assert.ok(!/<button/.test(html), 'cards carry no buttons');
Expand Down Expand Up @@ -144,7 +144,7 @@ assert.ok(!head.includes('asset-badge'), 'no status badge while creating');
reset('rules', { rules: [{ id: 'tapd', name: 'TAPD', projectId: 'p2', shared: true }] });
head = ctx.assetDetailHeadHTML(ctx.state.data.rules[0], {});
assert.deepStrictEqual(buttons(head), ['back']);
assert.ok(head.includes('来自 平台公共') && head.includes('只读 · 可直接在本项目使用'));
assert.ok(head.includes('来自 <span data-i18n-skip>平台公共</span>') && head.includes('只读 · 可直接在本项目使用'));

// ---------- Routes ----------
const route = hash => { ctx.location.hash = hash; return ctx.assetRouteId(); };
Expand Down
73 changes: 73 additions & 0 deletions web/i18n-en.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion web/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@
// rewrites, so a sentence typed by a person is not turned into mixed prose.
const DATA_SEL = '[data-i18n-data],.ai-user-bubble,.ai-think-body,.collab-process-body,.collab-list-item,.issue-title-cell b,#issueDetailTitle,.detail-desc,.comment-row p';
const ATTRS = ['placeholder', 'title', 'aria-label', 'data-tip', 'data-tooltip'];
// data-i18n-data-attrs="aria-label title" marks only those attributes as
// user data, for an element whose own copy must still be translated (a card
// labelled with the asset name it shows).
const dataAttr = (el, name) => !!el.closest(DATA_SEL) || (el.getAttribute('data-i18n-data-attrs') || '').split(/\s+/).includes(name);
const escape = s => s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const fragments = Object.keys(dict).filter(k => k.length > 1).sort((a, b) => b.length - a.length);
const fragmentRE = fragments.length ? new RegExp('(?<![\\u3400-\\u9fff])(?:' + fragments.map(escape).join('|') + ')(?![\\u3400-\\u9fff])', 'g') : null;
Expand Down Expand Up @@ -161,7 +165,7 @@
for (const name of ATTRS) {
const value = el.getAttribute && el.getAttribute(name);
if (value && HAN.test(value)) {
const next = el.closest(DATA_SEL) ? translateExact(value) : translate(value);
const next = dataAttr(el, name) ? translateExact(value) : translate(value);
if (next !== value) el.setAttribute(name, next);
}
}
Expand Down
Loading
Loading