diff --git a/changelog.d/3114-paused-chat-zh.fixed.md b/changelog.d/3114-paused-chat-zh.fixed.md new file mode 100644 index 000000000..48e56d48f --- /dev/null +++ b/changelog.d/3114-paused-chat-zh.fixed.md @@ -0,0 +1 @@ +A friend chat Bot Social paused now says so in the window’s language, title and “send your message again” line included ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index d2285ca52..d94cb94b7 100644 --- a/core/client.js +++ b/core/client.js @@ -383,6 +383,11 @@ var ZH = { "{n} holds · to {to}": "共 {n} 条 · 发给 {to}", "Auto-sent to {to}": "已自动发给 {to}", "Not sent: delivery failed": "未发出:发送失败", + // #3114 cut 28: the quiet card a paused friend chat draws, in every window. + "Chat paused": "聊天已暂停", + "Bot Social paused the last chat with this Bot.": "Bot Social 暂停了与这个 Bot 的上一次聊天。", + "Bot Social paused the last chat with this Bot ({reason}).": "Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。", + "{note} Send your message again: it starts a new chat.": "{note}请重新发送消息:这会开始一段新聊天。", "{from} → {to}": "{from} → {to}", "+{count} more": "另有 {count} 条", "{count} more not shown": "还有 {count} 条未显示", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index bacccb405..ed8cf1073 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -350,6 +350,11 @@ const ZH = { '{n} holds · to {to}': '共 {n} 条 · 发给 {to}', 'Auto-sent to {to}': '已自动发给 {to}', 'Not sent: delivery failed': '未发出:发送失败', + // #3114 cut 28: the quiet card a paused friend chat draws, in every window. + 'Chat paused': '聊天已暂停', + 'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。', + 'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。', + '{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。', '{from} → {to}': '{from} → {to}', '+{count} more': '另有 {count} 条', '{count} more not shown': '还有 {count} 条未显示', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index b054e709b..c309cc865 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -1,7 +1,6 @@ { "version": 1, "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: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.", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index c6236e45b..31055470c 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:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", "plugins/timeline/client.js:Looking back: window ends at {}.", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 9b0f9d6dc..93b690ed0 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,202 @@ const ZH = { +@@ -41,22 +41,207 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -1073,6 +1073,11 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + '{n} holds · to {to}': '共 {n} 条 · 发给 {to}', + 'Auto-sent to {to}': '已自动发给 {to}', + 'Not sent: delivery failed': '未发出:发送失败', ++ // #3114 cut 28: the quiet card a paused friend chat draws, in every window. ++ 'Chat paused': '聊天已暂停', ++ 'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。', ++ 'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。', ++ '{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。', + '{from} → {to}': '{from} → {to}', + '+{count} more': '另有 {count} 条', + '{count} more not shown': '还有 {count} 条未显示', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 374bb6888..b3e1d5c81 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,201 @@ var ZH = { +@@ -78,21 +78,206 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -337,6 +337,11 @@ diff --git a/client.js b/client.js + "{n} holds · to {to}": "共 {n} 条 · 发给 {to}", + "Auto-sent to {to}": "已自动发给 {to}", + "Not sent: delivery failed": "未发出:发送失败", ++ // #3114 cut 28: the quiet card a paused friend chat draws, in every window. ++ "Chat paused": "聊天已暂停", ++ "Bot Social paused the last chat with this Bot.": "Bot Social 暂停了与这个 Bot 的上一次聊天。", ++ "Bot Social paused the last chat with this Bot ({reason}).": "Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。", ++ "{note} Send your message again: it starts a new chat.": "{note}请重新发送消息:这会开始一段新聊天。", + "{from} → {to}": "{from} → {to}", + "+{count} more": "另有 {count} 条", + "{count} more not shown": "还有 {count} 条未显示", 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 b054e709b..c309cc865 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -1,7 +1,6 @@ { "version": 1, "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: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.", 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 c6236e45b..31055470c 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:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", "plugins/timeline/client.js:Looking back: window ends at {}.", diff --git a/plugins/social/client.js b/plugins/social/client.js index 07ff182dd..1adf7e6c1 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -4002,9 +4002,14 @@ window.__ModuleLoader__.load({ return () => { live = false; clearInterval(timer) } }, [handle]) if (!handle || !paused) return null + // The notice speaks the window's language (#3114); Bot Social's reason is server data and stays + // as it arrived. A host with no translator keeps today's English, word for word. + const note = paused.reason + ? tr('Bot Social paused the last chat with this Bot ({reason}).', { reason: paused.reason }) + : tr('Bot Social paused the last chat with this Bot.') return h('div', { className: 'fs-hold fs-chat-approval', 'data-flybot': 'chat-paused', role: 'status' }, - h('div', { className: 'fs-label' }, 'Chat paused'), - h('div', { className: 'fs-draft' }, `${paused.reason ? `Bot Social paused the last chat with this Bot (${paused.reason}).` : 'Bot Social paused the last chat with this Bot.'} Send your message again: it starts a new chat.`)) + h('div', { className: 'fs-label' }, tr('Chat paused')), + h('div', { className: 'fs-draft' }, tr('{note} Send your message again: it starts a new chat.', { note }))) } // + menu marks (#385), drawn like the host's line icons: people nearby, and a person to add. diff --git a/plugins/social/test/add-friend-i18n.test.js b/plugins/social/test/add-friend-i18n.test.js index 0e177f6aa..ec7ec66a3 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, 10, 47]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46]) // 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 52b0e6a1d..05b6ef25c 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, 10, 47]) + ], [12, 9, 46]) // 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/paused-chat-i18n.test.js b/plugins/social/test/paused-chat-i18n.test.js new file mode 100644 index 000000000..248bc47dc --- /dev/null +++ b/plugins/social/test/paused-chat-i18n.test.js @@ -0,0 +1,137 @@ +// #3114 cut 28: a friend chat Bot Social paused drew its whole quiet card in bare English — the title +// `Chat paused`, the sentence with or without Bot Social's reason, and the `Send your message again` +// line. This pins the card to the window's language: a zh window reads the dictionary's words with +// Bot Social's reason left as it arrived, a window whose host has no translator keeps today's English +// word for word, and the two baselines lose the draws those English strings 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 paused card reads what `social/paused` +// answered; the effects are inert, so the seeded answer is the render). +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()) +const card = states => { + const app = loadApp(zhWindow, states) + const nodes = walk(app.PausedChat({ bot: { remote: { handle: '@coder.bob.home' } } })) + return { + card: nodes[0], + texts: () => [ + directTexts(findNode(nodes, n => n.props?.className === 'fs-label')), + directTexts(findNode(nodes, n => n.props?.className === 'fs-draft')), + ], + } +} + +test('#3114 cut 28: the paused friend chat speaks the window’s language, with Bot Social’s reason', () => { + const { card: node, texts } = card([{ reason: 'loop detected' }]) + // The card is still the same quiet notice: same class, same mount point, still a status region. + assert.equal(node.props['data-flybot'], 'chat-paused') + assert.equal(node.props.role, 'status') + assert.equal(node.props.className, 'fs-hold fs-chat-approval') + // One reason sentence and one what-to-do-next sentence, both in the window's language. Bot + // Social's reason is server data and stays as it arrived, inside full-width brackets. + assert.deepEqual(texts(), [ + ['聊天已暂停'], + ['Bot Social 暂停了与这个 Bot 的上一次聊天(loop detected)。请重新发送消息:这会开始一段新聊天。'], + ]) +}) + +test('#3114 cut 28: a pause with no reason still reads as one sentence pair', () => { + const { texts } = card([{ pausedAt: '2026-11-19T23:00:00Z' }]) + // No reason: the sentence that carries it is gone, and the notice is still the two sentences. + assert.deepEqual(texts(), [ + ['聊天已暂停'], + ['Bot Social 暂停了与这个 Bot 的上一次聊天。请重新发送消息:这会开始一段新聊天。'], + ]) +}) + +// 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 paused notice', () => { + const app = loadApp(bareWindow, [{ reason: 'loop detected' }]) + const withReason = walk(app.PausedChat({ bot: { remote: { handle: '@coder.bob.home' } } })) + assert.deepEqual(directTexts(findNode(withReason, n => n.props?.className === 'fs-label')), ['Chat paused']) + assert.deepEqual(directTexts(findNode(withReason, n => n.props?.className === 'fs-draft')), [ + 'Bot Social paused the last chat with this Bot (loop detected). Send your message again: it starts a new chat.', + ]) + const plain = loadApp(bareWindow, [{}]) + const withoutReason = walk(plain.PausedChat({ bot: { remote: { handle: '@coder.bob.home' } } })) + assert.deepEqual(directTexts(findNode(withoutReason, n => n.props?.className === 'fs-draft')), [ + 'Bot Social paused the last chat with this Bot. Send your message again: it starts a new chat.', + ]) +}) + +// The card only exists for a friend's Bot chat that Bot Social actually paused: without a handle +// there is nothing to ask about, and a null answer draws nothing. +test('the card is still drawn only for a friend’s Bot chat that Bot Social paused', () => { + const app = loadApp(zhWindow, [{ reason: 'loop detected' }]) + assert.equal(app.PausedChat({}), null, 'no bot at all draws nothing') + assert.equal(app.PausedChat({ bot: { remote: {} } }), null, 'a bot with no handle draws nothing') + const unpaused = loadApp(zhWindow, [null]) + assert.equal(unpaused.PausedChat({ bot: { remote: { handle: '@coder.bob.home' } } }), null, 'an unpaused chat draws nothing') +}) + +// 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', ['Chat paused']], + ['i18n-template-draws.baseline.json', ['{} Send your message again: it starts a new chat.']], +] +const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries + +test('#3114 cut 28: 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, 9, 46]) + // Every new key is the dictionary's, each answer character for character — the full-width brackets + // and the `{note}` prefix with no space included, so a trimmed or half-width copy is caught here. + const keys = { + 'Chat paused': '聊天已暂停', + 'Bot Social paused the last chat with this Bot.': 'Bot Social 暂停了与这个 Bot 的上一次聊天。', + 'Bot Social paused the last chat with this Bot ({reason}).': 'Bot Social 暂停了与这个 Bot 的上一次聊天({reason})。', + '{note} Send your message again: it starts a new chat.': '{note}请重新发送消息:这会开始一段新聊天。', + } + assert.deepEqual(Object.entries(keys).map(([key]) => [key, zh[key]]), Object.entries(keys)) +}) diff --git a/plugins/social/test/room-auto-send-i18n.test.js b/plugins/social/test/room-auto-send-i18n.test.js index 8f84db5b6..e9a6f0d1f 100644 --- a/plugins/social/test/room-auto-send-i18n.test.js +++ b/plugins/social/test/room-auto-send-i18n.test.js @@ -102,7 +102,7 @@ test('#3114 cut 27: 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, 10, 47]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46]) // 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({ diff --git a/plugins/social/test/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js index 19e5395fa..fe3037c92 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, 10, 47]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46]) // 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 28848c99a..a1100b0ed 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, 10, 47]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 9, 46]) // 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({