diff --git a/changelog.d/3061-approve-all-english.fixed.md b/changelog.d/3061-approve-all-english.fixed.md new file mode 100644 index 000000000..87d139af1 --- /dev/null +++ b/changelog.d/3061-approve-all-english.fixed.md @@ -0,0 +1 @@ +The **Approve all** button in a chat's approval dock and the count in its tooltip now follow the window's language: a Chinese window reads 全部批准(3) and 共 3 条 · 发给 Eve, Bob instead of English, and an English window no longer reads 条 in its tooltip ([#3061](https://github.com/ThinkFlowLab/FlyBot/issues/3061)). diff --git a/core/client.js b/core/client.js index e93e55348..afedfc06a 100644 --- a/core/client.js +++ b/core/client.js @@ -265,6 +265,13 @@ var ZH = { "Not sent": "未发出", "{name} · Not sent": "{name} · 未发出", "Sent to {to}": "已发给 {to}", + // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in + // every window. + "Approve all ({n})": "全部批准({n})", + "1 hold": "共 1 条", + "{n} holds": "共 {n} 条", + "1 hold · to {to}": "共 1 条 · 发给 {to}", + "{n} holds · to {to}": "共 {n} 条 · 发给 {to}", "Auto-sent to {to}": "已自动发给 {to}", "Not sent: delivery failed": "未发出:发送失败", "{from} → {to}": "{from} → {to}", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 6bb4bb758..9c6aec24b 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -232,6 +232,13 @@ const ZH = { 'Not sent': '未发出', '{name} · Not sent': '{name} · 未发出', 'Sent to {to}': '已发给 {to}', + // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in + // every window. + 'Approve all ({n})': '全部批准({n})', + '1 hold': '共 1 条', + '{n} holds': '共 {n} 条', + '1 hold · to {to}': '共 1 条 · 发给 {to}', + '{n} holds · to {to}': '共 {n} 条 · 发给 {to}', 'Auto-sent to {to}': '已自动发给 {to}', 'Not sent: delivery failed': '未发出:发送失败', '{from} → {to}': '{from} → {to}', diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index ad3478298..40af9437f 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -1,7 +1,6 @@ { "version": 1, "entries": [ - "plugins/social/client.js:Approve all ({})", "plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.", "plugins/social/client.js:Auto-send my Bots' replies to {}", "plugins/social/client.js:Auto-send {} → room", @@ -28,8 +27,6 @@ "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/social/client.js:{} failed: {}", "plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.", - "plugins/social/client.js:{} 条", - "plugins/social/client.js:{} 条 · to {}", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#1", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#2", "plugins/timeline/client.js:Could not copy the report: {}", diff --git a/core/test/i18n-template-draws.test.js b/core/test/i18n-template-draws.test.js index 751829ee1..95bd291c7 100644 --- a/core/test/i18n-template-draws.test.js +++ b/core/test/i18n-template-draws.test.js @@ -61,12 +61,18 @@ test('the plugins on main are pinned, and a template draw nobody pinned fails', assert.equal(Number.parseInt(out.stdout.trimEnd().split('\n').at(-1), 10), current.size, 'the summary line counts the pins') }) -// Acceptance: the list names the Approve-all row on main, and its identity is the skeleton the reader -// sees, never the line a comment above it happens to move. -test('the Approve-all template on main is a member, and 12 comment lines leave the set identical', () => { - const file = fileURLToPath(new URL('../../plugins/social/client.js', import.meta.url)) - const source = readFileSync(file, 'utf8') - const member = scanTemplateDraws().filter(entry => entry.file === 'plugins/social/client.js' && entry.key === '{} 条 · to {}') +// Acceptance: a row with two holes is a member of the list, and its identity is the skeleton the reader +// sees, never the line a comment above it happens to move. The Approve-all draw this used to read on main +// now goes through `tr()` (#3061), so the same shape is pinned here as a source rather than borrowed from +// the repository — the scanner's promise is about any source, and the copy on main is no longer a draw. +test('a two-hole template draw is a member, and 12 comment lines leave the set identical', () => { + const source = [ + 'const approveAllTitle = approveRecipients.length ? `${n} 条 · to ${who}` : `${n} 条`', + 'const approveAllLabel = `Approve all (${n})`', + "h('button', { title: approveAllTitle }, approveAllLabel)", + '', + ].join('\n') + const member = templateDraws(source, 'plugins/social/client.js').filter(entry => entry.key === '{} 条 · to {}') assert.equal(member.length, 1, 'the Approve-all row names its two holes') const shifted = `${'// a comment above the draw\n'.repeat(12)}${source}` const keys = entries => entries.map(entry => `${entry.file}\u0000${entry.key}`).sort() diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 3823597be..c5b627456 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -852,7 +852,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js Content: '内容', 'Referenced {labels}': '引用了 {labels}', ', ': '、', -@@ -41,22 +41,86 @@ const ZH = { +@@ -41,22 +41,93 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -912,6 +912,13 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'Not sent': '未发出', + '{name} · Not sent': '{name} · 未发出', + 'Sent to {to}': '已发给 {to}', ++ // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in ++ // every window. ++ 'Approve all ({n})': '全部批准({n})', ++ '1 hold': '共 1 条', ++ '{n} holds': '共 {n} 条', ++ '1 hold · to {to}': '共 1 条 · 发给 {to}', ++ '{n} holds · to {to}': '共 {n} 条 · 发给 {to}', + 'Auto-sent to {to}': '已自动发给 {to}', + 'Not sent: delivery failed': '未发出:发送失败', + '{from} → {to}': '{from} → {to}', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 250e3eba1..47380c976 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -160,7 +160,7 @@ diff --git a/client.js b/client.js Content: "内容", "Referenced {labels}": "引用了 {labels}", ", ": "、", -@@ -78,21 +78,85 @@ var ZH = { +@@ -78,21 +78,92 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -219,6 +219,13 @@ diff --git a/client.js b/client.js + "Not sent": "未发出", + "{name} · Not sent": "{name} · 未发出", + "Sent to {to}": "已发给 {to}", ++ // #3061: the approve-all button and its title, which used to draw english (and a chinese count) in ++ // every window. ++ "Approve all ({n})": "全部批准({n})", ++ "1 hold": "共 1 条", ++ "{n} holds": "共 {n} 条", ++ "1 hold · to {to}": "共 1 条 · 发给 {to}", ++ "{n} holds · to {to}": "共 {n} 条 · 发给 {to}", + "Auto-sent to {to}": "已自动发给 {to}", + "Not sent: delivery failed": "未发出:发送失败", + "{from} → {to}": "{from} → {to}", diff --git a/patches/ds-bot/files/test/i18n-template-draws.baseline.json b/patches/ds-bot/files/test/i18n-template-draws.baseline.json index ad3478298..40af9437f 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -1,7 +1,6 @@ { "version": 1, "entries": [ - "plugins/social/client.js:Approve all ({})", "plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.", "plugins/social/client.js:Auto-send my Bots' replies to {}", "plugins/social/client.js:Auto-send {} → room", @@ -28,8 +27,6 @@ "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/social/client.js:{} failed: {}", "plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.", - "plugins/social/client.js:{} 条", - "plugins/social/client.js:{} 条 · to {}", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#1", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#2", "plugins/timeline/client.js:Could not copy the report: {}", diff --git a/patches/ds-bot/files/test/i18n-template-draws.test.js b/patches/ds-bot/files/test/i18n-template-draws.test.js index 751829ee1..95bd291c7 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.test.js +++ b/patches/ds-bot/files/test/i18n-template-draws.test.js @@ -61,12 +61,18 @@ test('the plugins on main are pinned, and a template draw nobody pinned fails', assert.equal(Number.parseInt(out.stdout.trimEnd().split('\n').at(-1), 10), current.size, 'the summary line counts the pins') }) -// Acceptance: the list names the Approve-all row on main, and its identity is the skeleton the reader -// sees, never the line a comment above it happens to move. -test('the Approve-all template on main is a member, and 12 comment lines leave the set identical', () => { - const file = fileURLToPath(new URL('../../plugins/social/client.js', import.meta.url)) - const source = readFileSync(file, 'utf8') - const member = scanTemplateDraws().filter(entry => entry.file === 'plugins/social/client.js' && entry.key === '{} 条 · to {}') +// Acceptance: a row with two holes is a member of the list, and its identity is the skeleton the reader +// sees, never the line a comment above it happens to move. The Approve-all draw this used to read on main +// now goes through `tr()` (#3061), so the same shape is pinned here as a source rather than borrowed from +// the repository — the scanner's promise is about any source, and the copy on main is no longer a draw. +test('a two-hole template draw is a member, and 12 comment lines leave the set identical', () => { + const source = [ + 'const approveAllTitle = approveRecipients.length ? `${n} 条 · to ${who}` : `${n} 条`', + 'const approveAllLabel = `Approve all (${n})`', + "h('button', { title: approveAllTitle }, approveAllLabel)", + '', + ].join('\n') + const member = templateDraws(source, 'plugins/social/client.js').filter(entry => entry.key === '{} 条 · to {}') assert.equal(member.length, 1, 'the Approve-all row names its two holes') const shifted = `${'// a comment above the draw\n'.repeat(12)}${source}` const keys = entries => entries.map(entry => `${entry.file}\u0000${entry.key}`).sort() diff --git a/plugins/social/client.js b/plugins/social/client.js index c80e658d8..bb77bd235 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -2538,6 +2538,9 @@ window.__ModuleLoader__.load({ function ChatApprovalDock({ sessionId, roster, room, bot, actions, claim, t } = {}) { useStyles() + // #3061: the dock's own strings read the window's dictionary. The host hands the translator down + // as a prop; without one the module translator (the one every other line here uses) answers. + const trIn = (text, params) => (typeof t === 'function' ? t(text, params) : tr(text, params)) const locked = readOnlyReason(roster) const [items, setItems] = useState([]) const [local, setLocal] = useState([]) @@ -2780,10 +2783,13 @@ window.__ModuleLoader__.load({ // cannot be undone is readable before it. const toApprove = mine.filter(waiting) const approveRecipients = recipientNames(toApprove) - const approveAllLabel = `Approve all (${toApprove.length})` + // #3061: both strings go through the window's dictionary; the source is english and the count + // is the holds the click sends, the names are the people it reaches. + const approveAllLabel = trIn('Approve all ({n})', { n: toApprove.length }) + // A failed hold counts in `mine` but not in the send, so one hold can be the whole batch (#3015). const approveAllTitle = approveRecipients.length - ? `${toApprove.length} 条 · to ${approveRecipients.join(', ')}` - : `${toApprove.length} 条` + ? trIn(toApprove.length === 1 ? '1 hold · to {to}' : '{n} holds · to {to}', { n: toApprove.length, to: approveRecipients.join(', ') }) + : trIn(toApprove.length === 1 ? '1 hold' : '{n} holds', { n: toApprove.length }) // #1640: this card is drawn exactly when the room's own card is decided somewhere this chat does // not draw. A held reply is decided on its own bubble here (#418); a Bot's hold is decided in a // chat this person can open (#254). A card we cannot place keeps the neutral sentence: the dock diff --git a/plugins/social/test/social.test.js b/plugins/social/test/social.test.js index 1f898e337..f139a9a1a 100644 --- a/plugins/social/test/social.test.js +++ b/plugins/social/test/social.test.js @@ -4549,7 +4549,7 @@ test('#260: Approve all approves Bot Social holds too, not only local ones', asy const all = tree.find(node => node.props['data-flybot'] === 'approve-all') assert.ok(all, 'Approve all is offered for Bot Social holds (they carry status: pending)') assert.deepEqual(all.children, ['Approve all (2)'], `the label carries the count, saw ${JSON.stringify(all.children)}`) - assert.equal(all.props.title, '2 条 · to Bob', `the title names the person, saw ${JSON.stringify(all.props.title)}`) + assert.equal(all.props.title, '2 holds · to Bob', `the title names the person, saw ${JSON.stringify(all.props.title)}`) await all.props.onClick() const decided = calls.filter(([endpoint]) => endpoint === 'social/decide-approval').map(([, payload]) => payload.approvalId) assert.deepEqual(decided.sort(), ['s1', 's2']) @@ -4565,7 +4565,46 @@ test('#3011: Approve all says how many holds it sends and to whom', () => { const all = tree.find(node => node.props['data-flybot'] === 'approve-all') assert.ok(all, 'Approve all is offered for three waiting holds') assert.deepEqual(all.children, ['Approve all (3)'], `the label carries the count, saw ${JSON.stringify(all.children)}`) - assert.equal(all.props.title, '3 条 · to Eve, Bob', `the title names each person once, saw ${JSON.stringify(all.props.title)}`) + assert.equal(all.props.title, '3 holds · to Eve, Bob', `the title names each person once, saw ${JSON.stringify(all.props.title)}`) +}) + +test('#3061: Approve all reads its label and tooltip in the language of the window', async () => { + const { walk, pluginOf } = loadSocialClient(async () => ({})) + const { DICTIONARY } = await import('../../../core/src/client/i18n.js') + // The same translator the host hands a plugin: the window's dictionary, then the english keys as + // written when a window has no entry. + const translate = (language) => (text, params) => { + const used = DICTIONARY[language]?.[text] ?? text + return String(used).replace(/\{(\w+)\}/g, (_, name) => String(params?.[name] ?? '')) + } + const hold = (id, to, toName) => ({ id, kind: 'outbound_message', status: 'pending', from: 'Chief', to, toName, text: id }) + const items = [hold('h1', '@eve.home', 'Eve'), hold('h2', '@bob.home', 'Bob'), hold('h3', '@eve.home', 'Eve')] + const room = { id: 'room-1', participants: [{ handle: '@eve.home' }, { handle: '@bob.home' }] } + const draw = (items, t) => walk(pluginOf([items, [], true, true]) + .ChatApprovalDock({ bot: { id: 'mine' }, roster: { bots: [] }, room, t })) + .find(node => node.props['data-flybot'] === 'approve-all') + + // Three holds, two people: the english window reads the source strings. + const en = draw(items) + assert.deepEqual(en.children, ['Approve all (3)'], `the english label carries the count, saw ${JSON.stringify(en.children)}`) + assert.equal(en.props.title, '3 holds · to Eve, Bob', `the english title names each person once, saw ${JSON.stringify(en.props.title)}`) + + // The chinese window reads the same sentence from its dictionary, so neither string stays English. + const zh = draw(items, translate('zh')) + assert.deepEqual(zh.children, ['全部批准(3)'], `the chinese label follows the window, saw ${JSON.stringify(zh.children)}`) + assert.equal(zh.props.title, '共 3 条 · 发给 Eve, Bob', `the chinese title follows the window, saw ${JSON.stringify(zh.props.title)}`) + + // Holds whose person the dock cannot name keep the count alone — and that sentence follows too. + const unnamed = [ + { id: 'u1', kind: 'outbound_message', status: 'pending', from: 'Chief', to: '@eve.home', text: 'u1' }, + { id: 'u2', kind: 'outbound_message', status: 'pending', from: 'Chief', to: '@bob.home', text: 'u2' }, + ] + const enAlone = draw(unnamed) + assert.deepEqual(enAlone.children, ['Approve all (2)'], `the english label counts both, saw ${JSON.stringify(enAlone.children)}`) + assert.equal(enAlone.props.title, '2 holds', `the english count alone, saw ${JSON.stringify(enAlone.props.title)}`) + const zhAlone = draw(unnamed, translate('zh')) + assert.deepEqual(zhAlone.children, ['全部批准(2)'], `the chinese label counts both, saw ${JSON.stringify(zhAlone.children)}`) + assert.equal(zhAlone.props.title, '共 2 条', `the chinese count follows the window, saw ${JSON.stringify(zhAlone.props.title)}`) }) test('#3015: Approve all counts the holds it sends, not a failed one drawn beside them', async () => { @@ -4582,7 +4621,7 @@ test('#3015: Approve all counts the holds it sends, not a failed one drawn besid const all = tree.find(node => node.props['data-flybot'] === 'approve-all') assert.ok(all, 'Approve all is offered while one hold is waiting') assert.deepEqual(all.children, ['Approve all (1)'], `the count is the holds the click sends, saw ${JSON.stringify(all.children)}`) - assert.equal(all.props.title, '1 条 · to Eve', `the title names only the person it sends to, saw ${JSON.stringify(all.props.title)}`) + assert.equal(all.props.title, '1 hold · to Eve', `the title names only the person it sends to, saw ${JSON.stringify(all.props.title)}`) await all.props.onClick() const decisions = calls.filter(([endpoint]) => endpoint === 'social/decide-approval' || endpoint === 'decide') assert.deepEqual(decisions.map(([endpoint, payload]) => [endpoint, payload.approvalId ?? payload.id]), [['social/decide-approval', 'w1']], `only the waiting hold is sent, saw ${JSON.stringify(decisions)}`) @@ -5087,7 +5126,7 @@ test('#114: in-chat dock lists drafts with Approve all; others see a waiting lin const approveAll = tree.find(n => n.props['data-flybot'] === 'approve-all') assert.ok(approveAll, 'Approve all is offered for the two drafts') assert.ok(approveAll.children.includes('Approve all (2)'), `the label carries the count, saw ${JSON.stringify(approveAll.children)}`) - assert.equal(approveAll.props.title, '2 条', `with no person named the title is the count alone, saw ${JSON.stringify(approveAll.props.title)}`) + assert.equal(approveAll.props.title, '2 holds', `with no person named the title is the count alone, saw ${JSON.stringify(approveAll.props.title)}`) assert.equal(tree.filter(n => n.props['data-flybot'] === 'chat-approval').length, 2) assert.ok(tree.some(n => n.props.className === 'fs-draft' && n.children.includes('one'))) assert.ok(tree.some(n => n.props.className === 'fs-sub' && n.children.includes('Chief → Hsliu')))