From a9aa55614fadc9b2dd728f12de069f83ff5e9afc Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Fri, 20 Nov 2026 08:08:56 +0800 Subject: [PATCH] Read the room's auto-send switch and Past rooms in the window's language (#3114) Fixes #3231 Part of #3114 Docs-not-needed: user-visible zh copy only; no subsystem behaviour, API or ownership changed. --- changelog.d/3114-room-auto-send-zh.fixed.md | 1 + core/client.js | 5 + core/src/client/i18n.js | 5 + core/test/i18n-missing-entries.baseline.json | 1 - core/test/i18n-template-draws.baseline.json | 2 - patches/ds-bot/0001-core-fixes.patch | 7 +- patches/ds-bot/0008-client-bundle.patch | 7 +- .../test/i18n-missing-entries.baseline.json | 1 - .../test/i18n-template-draws.baseline.json | 2 - plugins/social/client.js | 7 +- plugins/social/test/add-friend-i18n.test.js | 2 +- .../social/test/friend-settings-i18n.test.js | 2 +- .../social/test/room-auto-send-i18n.test.js | 119 ++++++++++++++++++ plugins/social/test/sharing-page-i18n.test.js | 2 +- .../social/test/sharing-rooms-i18n.test.js | 2 +- 15 files changed, 150 insertions(+), 15 deletions(-) create mode 100644 changelog.d/3114-room-auto-send-zh.fixed.md create mode 100644 plugins/social/test/room-auto-send-i18n.test.js diff --git a/changelog.d/3114-room-auto-send-zh.fixed.md b/changelog.d/3114-room-auto-send-zh.fixed.md new file mode 100644 index 000000000..a96e90e99 --- /dev/null +++ b/changelog.d/3114-room-auto-send-zh.fixed.md @@ -0,0 +1 @@ +The face-to-face room’s Auto-send switches (`Auto-send Chief → room` and the checkbox’s own name) and the sidebar’s `Past rooms` fold now read in the window’s language instead of English ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index e3f6603b5..d2285ca52 100644 --- a/core/client.js +++ b/core/client.js @@ -362,6 +362,11 @@ var ZH = { // #3032: the four approval-card controls that were still drawn as bare English. "Waiting for the owner's approval": "等待 owner 批准", "Auto-send from now on": "以后自动发送", + // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold. + "Auto-send {bot} → room": "{bot} 发给房间的消息自动发送", + "Auto-send {bot}'s room messages": "自动发送 {bot} 在房间里的消息", + "my Bot": "我的 Bot", + "Past rooms": "历史房间", Decline: "拒绝", pending: "等待中", "Decide on the reply bubble above.": "在上面的回复气泡里批准。", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index d7e1d7d67..bacccb405 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -329,6 +329,11 @@ const ZH = { // #3032: the four approval-card controls that were still drawn as bare English. "Waiting for the owner's approval": '等待 owner 批准', 'Auto-send from now on': '以后自动发送', + // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold. + 'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送', + "Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息', + 'my Bot': '我的 Bot', + 'Past rooms': '历史房间', Decline: '拒绝', pending: '等待中', 'Decide on the reply bubble above.': '在上面的回复气泡里批准。', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index 55cf94e87..b054e709b 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -3,7 +3,6 @@ "entries": [ "plugins/social/client.js:Chat paused", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", - "plugins/social/client.js:Past rooms", "plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.", "plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.", "plugins/social/client.js:Social#1", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index f717ab608..c6236e45b 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -1,8 +1,6 @@ { "version": 1, "entries": [ - "plugins/social/client.js:Auto-send {} → room", - "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index e66666693..9b0f9d6dc 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -895,7 +895,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js Content: '内容', 'Referenced {labels}': '引用了 {labels}', ', ': '、', -@@ -41,22 +41,197 @@ const ZH = { +@@ -41,22 +41,202 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -1052,6 +1052,11 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + // #3032: the four approval-card controls that were still drawn as bare English. + "Waiting for the owner's approval": '等待 owner 批准', + 'Auto-send from now on': '以后自动发送', ++ // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold. ++ 'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送', ++ "Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息', ++ 'my Bot': '我的 Bot', ++ 'Past rooms': '历史房间', + Decline: '拒绝', + pending: '等待中', + 'Decide on the reply bubble above.': '在上面的回复气泡里批准。', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 6053b48a2..374bb6888 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,196 @@ var ZH = { +@@ -78,21 +78,201 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -316,6 +316,11 @@ diff --git a/client.js b/client.js + // #3032: the four approval-card controls that were still drawn as bare English. + "Waiting for the owner's approval": "等待 owner 批准", + "Auto-send from now on": "以后自动发送", ++ // #3114 cut 27: the face-to-face room's Auto-send switch and the sidebar's Past rooms fold. ++ "Auto-send {bot} → room": "{bot} 发给房间的消息自动发送", ++ "Auto-send {bot}'s room messages": "自动发送 {bot} 在房间里的消息", ++ "my Bot": "我的 Bot", ++ "Past rooms": "历史房间", + Decline: "拒绝", + pending: "等待中", + "Decide on the reply bubble above.": "在上面的回复气泡里批准。", diff --git a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json index 55cf94e87..b054e709b 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -3,7 +3,6 @@ "entries": [ "plugins/social/client.js:Chat paused", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", - "plugins/social/client.js:Past rooms", "plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.", "plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.", "plugins/social/client.js:Social#1", 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 f717ab608..c6236e45b 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -1,8 +1,6 @@ { "version": 1, "entries": [ - "plugins/social/client.js:Auto-send {} → room", - "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", diff --git a/plugins/social/client.js b/plugins/social/client.js index 4c57475a8..07ff182dd 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -555,15 +555,16 @@ window.__ModuleLoader__.load({ const AUTO_SEND_NOTE = "Don't ask each time." function FaceAutoSend({ on, busy, onChange, bot } = {}) { + const who = bot || tr('my Bot') return h('label', { className: 'fs-auto fs-face-auto', title: tr(AUTO_SEND_NOTE), 'data-flybot': 'face-auto-bot' }, h('input', { type: 'checkbox', checked: on === true, disabled: !!busy, - 'aria-label': `Auto-send ${bot || 'my Bot'}'s room messages`, + 'aria-label': tr("Auto-send {bot}'s room messages", { bot: who }), onChange: e => onChange?.(e.target.checked), }), - `Auto-send ${bot || 'my Bot'} → room`) + tr('Auto-send {bot} → room', { bot: who })) } // Leave asks once (#182): leaving ends my part in the room for good. @@ -3096,7 +3097,7 @@ window.__ModuleLoader__.load({ h('div', { className: 'fs-past', 'data-flybot': 'face-past' }, h('button', { type: 'button', className: 'fs-past-head', 'aria-expanded': pastOpen, onClick: togglePast }, h('span', { className: 'fs-chev', 'aria-hidden': true, 'data-closed': pastOpen ? undefined : true }, '▾'), - 'Past rooms', + tr('Past rooms'), h('span', { className: 'fs-count' }, String(past.length))), pastOpen ? past.map(room => card(room, true)) : null)) } diff --git a/plugins/social/test/add-friend-i18n.test.js b/plugins/social/test/add-friend-i18n.test.js index 274825d10..0e177f6aa 100644 --- a/plugins/social/test/add-friend-i18n.test.js +++ b/plugins/social/test/add-friend-i18n.test.js @@ -116,7 +116,7 @@ test('#3114 cut 22: the baselines lose these draws and the dictionary gains the assert.deepEqual(still, [], `${file.replace('.baseline.json', '')} still pins ${still[0]}`) } // The three baselines shrink by exactly these draws and nothing else does: the ratchet's numbers. - assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47]) // Every new key is the dictionary's, and each answers with Chinese. for (const key of [ 'Accept an invite', 'Invite a friend', 'Paste invite link or code', diff --git a/plugins/social/test/friend-settings-i18n.test.js b/plugins/social/test/friend-settings-i18n.test.js index 0ffd0fc0b..52b0e6a1d 100644 --- a/plugins/social/test/friend-settings-i18n.test.js +++ b/plugins/social/test/friend-settings-i18n.test.js @@ -149,7 +149,7 @@ test('#3114 cut 23: the two baselines lose these draws and nothing else', () => entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length, - ], [12, 12, 48]) + ], [12, 10, 47]) // People with access is reused, never added twice; the same for the friend's own fallback name. assert.equal(zh['Your friend'], '你的朋友') }) diff --git a/plugins/social/test/room-auto-send-i18n.test.js b/plugins/social/test/room-auto-send-i18n.test.js new file mode 100644 index 000000000..8f84db5b6 --- /dev/null +++ b/plugins/social/test/room-auto-send-i18n.test.js @@ -0,0 +1,119 @@ +// #3114 cut 27: the face-to-face room head drew its per-Bot Auto-send switch as bare English +// (`Auto-send Chief → room` and the checkbox's own name `Auto-send Chief's room messages`), and the +// sidebar's folded list of ended rooms drew `Past rooms` the same way. This pins them: a zh window +// reads the dictionary's words, a window whose host has no translator keeps today's English word for +// word, and the two baselines lose the three pins those draws held. +import assert from 'node:assert/strict' +import { readFileSync } from 'node:fs' +import { test } from 'node:test' +import { runInNewContext } from 'node:vm' +import { DICTIONARY } from '../../../core/src/client/i18n.js' + +const zh = DICTIONARY.zh +// The language a window runs in: `t` answers with the Chinese dictionary for a key it carries and +// echoes anything else, which is what the host's own translator does for an entry it lacks. +const translator = (text, params) => { + const translated = Object.hasOwn(zh, text) ? zh[text] : String(text) + return params ? translated.replace(/\{(\w+)\}/g, (match, name) => (name in params ? String(params[name]) : match)) : translated +} +const zhWindow = { t: translator, slots: { register: () => () => {} }, call: async () => ({}) } +const bareWindow = { slots: { register: () => () => {} }, call: async () => ({}) } + +// The client is a classic script that registers its factory on `window`, and the plugin reads +// `__flybot__` off the global object at render time — so the sandbox is that global object. +// `states` seeds the component's useState calls in order (the room list reads its loaded rooms). +function loadApp(flybot, states = []) { + const registered = [] + const sandbox = { window: { __ModuleLoader__: { load: entry => registered.push(entry) } }, console, setTimeout, clearTimeout, setInterval, clearInterval } + sandbox.globalThis = sandbox + sandbox.__flybot__ = flybot + runInNewContext(readFileSync(new URL('../client.js', import.meta.url), 'utf8'), sandbox) + let seed = 0 + const app = registered[0].factory(() => ({ + createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }), + Fragment: 'F', useEffect() {}, useRef: value => ({ current: value }), useMemo: fn => fn(), + useState: value => [seed < states.length ? states[seed++] : value, () => {}], + })) + return app +} +// These are plain render functions once the effects are inert, so the tree is the render. +function walk(node, all = []) { + if (!node || typeof node !== 'object') return all + if (typeof node.type === 'function') return walk(node.type(node.props), all) + all.push(node) + for (const child of node.children ?? []) walk(child, all) + return all +} +const findNode = (nodes, match) => nodes.find(match) +const directTexts = node => (node?.children ?? []).filter(child => typeof child === 'string' && child.trim()) + +test('#3114 cut 27: the room head’s Auto-send switches speak the window’s language', () => { + const app = loadApp(zhWindow) + const nodes = walk(app.FaceAutoSend({ bot: 'Chief', on: true })) + // The switch keeps the note it already had, and its two names come from the dictionary. + assert.equal(nodes[0].props.title, '不要每次都问。', 'the tooltip is still "Don\'t ask each time."') + assert.equal(findNode(nodes, n => n.props?.type === 'checkbox')?.props['aria-label'], '自动发送 Chief 在房间里的消息') + assert.deepEqual(directTexts(nodes[0]), ['Chief 发给房间的消息自动发送']) + // A Bot whose name did not arrive falls back through the dictionary too, not to bare `my Bot`. + const unknown = walk(app.FaceAutoSend({})) + assert.deepEqual(directTexts(unknown[0]), ['我的 Bot 发给房间的消息自动发送']) + assert.equal(findNode(unknown, n => n.props?.type === 'checkbox')?.props['aria-label'], '自动发送 我的 Bot 在房间里的消息') +}) + +test('#3114 cut 27: the sidebar’s Past rooms fold speaks the window’s language', () => { + // One ended room: the fold draws its head and the count, and the section is still `fs-past`. + const room = { id: 'g1', faceRoomId: 'frm_1', status: 'closed', name: 'Den' } + const app = loadApp(zhWindow, [[room], false]) + const nodes = walk(app.FaceRooms({})) + const head = findNode(nodes, n => n.props?.className === 'fs-past-head') + assert.deepEqual(directTexts(head), ['历史房间']) + assert.equal(findNode(nodes, n => n.props?.className === 'fs-count')?.children[0], '1', 'the count is still the number of ended rooms') + assert.ok(findNode(nodes, n => n.props?.['data-flybot'] === 'face-past'), 'the fold is still `face-past`') +}) + +// A host with no translator keeps the English it drew before this change, character for character — +// `tr()` replaces a string only when the host answers for it. +test('a host with no translator keeps today’s English in the room head and the fold', () => { + const app = loadApp(bareWindow) + const named = walk(app.FaceAutoSend({ bot: 'Chief' })) + assert.deepEqual(directTexts(named[0]), ['Auto-send Chief → room']) + assert.equal(findNode(named, n => n.props?.type === 'checkbox')?.props['aria-label'], "Auto-send Chief's room messages") + const unknown = walk(app.FaceAutoSend({})) + assert.deepEqual(directTexts(unknown[0]), ['Auto-send my Bot → room']) + const room = { id: 'g1', faceRoomId: 'frm_1', status: 'closed', name: 'Den' } + const fold = loadApp(bareWindow, [[room], false]) + const head = findNode(walk(fold.FaceRooms({})), n => n.props?.className === 'fs-past-head') + assert.deepEqual(directTexts(head), ['Past rooms']) +}) + +// The baselines may only shrink, and an entry leaves when its zh key lands — a draw that is +// translated no longer needs pinning. The files are read as the repository ships them. +const pinned = [ + ['i18n-missing-entries.baseline.json', ['Past rooms']], + ['i18n-template-draws.baseline.json', ['Auto-send {} → room', "Auto-send {}'s room messages"]], +] +const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries + +test('#3114 cut 27: the two baselines lose these draws and the dictionary gains the keys', () => { + for (const [file, keys] of pinned) { + const entries = entriesOf(file) + const still = keys.map(key => `plugins/social/client.js:${key}`).filter(id => entries.includes(id)) + assert.deepEqual(still, [], `${file.replace('.baseline.json', '')} still pins ${still[0]}`) + } + // The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's + // numbers, and a later cut that moves them moves these numbers with it. + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47]) + // Every new key is the dictionary's, each answer character for character — the arrow's single + // spaces and the straight `'` included, so a trimmed or curly-quoted copy is caught here. + assert.deepEqual(Object.entries({ + 'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送', + "Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息', + 'my Bot': '我的 Bot', + 'Past rooms': '历史房间', + }).map(([key]) => [key, zh[key]]), Object.entries({ + 'Auto-send {bot} → room': '{bot} 发给房间的消息自动发送', + "Auto-send {bot}'s room messages": '自动发送 {bot} 在房间里的消息', + 'my Bot': '我的 Bot', + 'Past rooms': '历史房间', + })) +}) diff --git a/plugins/social/test/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js index 3a1b170ff..19e5395fa 100644 --- a/plugins/social/test/sharing-page-i18n.test.js +++ b/plugins/social/test/sharing-page-i18n.test.js @@ -145,7 +145,7 @@ test('#3114 cut 20: the three baselines lose these draws', () => { } // The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's // numbers, and a later cut that moves them moves these numbers with it. - assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47]) // A host with no translator keeps the English it drew before this change, character for // character — `tr()` replaces a string only when the host answers for it. diff --git a/plugins/social/test/sharing-rooms-i18n.test.js b/plugins/social/test/sharing-rooms-i18n.test.js index ef4e0e812..28848c99a 100644 --- a/plugins/social/test/sharing-rooms-i18n.test.js +++ b/plugins/social/test/sharing-rooms-i18n.test.js @@ -123,7 +123,7 @@ test('#3114 cut 26: the two baselines lose these draws and the dictionary gains } // The baselines shrink by exactly these draws and nothing else does: the totals are the ratchet's // numbers, and a later cut that moves them moves these numbers with it. - assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 12, 48]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 10, 47]) // Every new key is the dictionary's, each answer character for character — the four keys that end // in a space and the one that starts with it included, so a trimmed copy is caught here. assert.deepEqual(Object.entries({