diff --git a/changelog.d/3114-face-invite-card-i18n.fixed.md b/changelog.d/3114-face-invite-card-i18n.fixed.md new file mode 100644 index 000000000..759708a8d --- /dev/null +++ b/changelog.d/3114-face-invite-card-i18n.fixed.md @@ -0,0 +1 @@ +The invite card inside an open face-to-face room now follows the window's language: its Link ready button, the QR's name and hint, the Copied state, the no-deadline line and the error a mint with no link comes back with ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index 738f82fc7..6b48972f4 100644 --- a/core/client.js +++ b/core/client.js @@ -1817,7 +1817,13 @@ var HOST_ZH = { "{name} is now a friend.": "{name} 现在成了你的朋友。", "Declined {name}.": "已拒绝 {name}。", "{what} failed: {why}": "{what} 失败:{why}", - "Your friend": "你的朋友" + "Your friend": "你的朋友", + // #3114 cut 25: the invite card in an open face-to-face room. + "Link ready": "链接已就绪", + "QR code for this room invite": "这个房间邀请的二维码", + "Scan to open this room": "扫码打开这个房间", + "Anyone with the link can join while the room is open.": "只要房间还开着,拿到链接的人都能加入。", + "Bot Social did not send an invite. Try again.": "Bot Social 没有发来邀请,请重试。" }; Object.assign(ZH, HOST_ZH); var fill = (text2, params) => params ? text2.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text2; diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 9f4de4f95..7bac79030 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -1778,6 +1778,12 @@ const HOST_ZH = { 'Declined {name}.': '已拒绝 {name}。', '{what} failed: {why}': '{what} 失败:{why}', 'Your friend': '你的朋友', + // #3114 cut 25: the invite card in an open face-to-face room. + 'Link ready': '链接已就绪', + 'QR code for this room invite': '这个房间邀请的二维码', + 'Scan to open this room': '扫码打开这个房间', + 'Anyone with the link can join while the room is open.': '只要房间还开着,拿到链接的人都能加入。', + 'Bot Social did not send an invite. Try again.': 'Bot Social 没有发来邀请,请重试。', } Object.assign(ZH, HOST_ZH) diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index 58632ba1b..9718dfb97 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -2,15 +2,11 @@ "version": 1, "entries": [ "plugins/social/client.js: +{} more", - "plugins/social/client.js:Anyone with the link can join while the room is open.", "plugins/social/client.js:Chat paused", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", "plugins/social/client.js:In use in {} room{}: ", - "plugins/social/client.js:Link ready", "plugins/social/client.js:Past rooms", - "plugins/social/client.js:QR code for this room invite", "plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.", - "plugins/social/client.js:Scan to open this room", "plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.", "plugins/social/client.js:Social#1", "plugins/social/client.js:Social#2", diff --git a/core/test/i18n-plugins.baseline.json b/core/test/i18n-plugins.baseline.json index 45d91db2c..3189796ff 100644 --- a/core/test/i18n-plugins.baseline.json +++ b/core/test/i18n-plugins.baseline.json @@ -2,8 +2,7 @@ "version": 1, "entries": [ "plugins/social/client.js:Close", - "plugins/social/client.js:Copied#1", - "plugins/social/client.js:Copied#2", + "plugins/social/client.js:Copied", "plugins/social/client.js:Copy", "plugins/social/client.js:Your Bot Social handle", "plugins/timeline/client.js:Close", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 3952b8dc5..b95b86694 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -2055,7 +2055,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js 'The admin must be a member of the group': '管理员必须是群成员', 'Unknown group chat': '找不到这个群聊', 'Hand the admin role to another member instead of leaving the group without one': '请把管理员交给其他成员,不要让群聊没有管理员', -@@ -905,6 +905,34 @@ const HOST_ZH = { +@@ -905,6 +905,40 @@ const HOST_ZH = { 'Write the entry to save.': '请写下要保存的内容。', 'This DeepSeek Harness has no folder chooser': '这个 DeepSeek Harness 没有文件夹选择窗口', 'This DeepSeek Harness cannot list folders': '这个 DeepSeek Harness 不能列出文件夹', @@ -2087,6 +2087,12 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'Declined {name}.': '已拒绝 {name}。', + '{what} failed: {why}': '{what} 失败:{why}', + 'Your friend': '你的朋友', ++ // #3114 cut 25: the invite card in an open face-to-face room. ++ 'Link ready': '链接已就绪', ++ 'QR code for this room invite': '这个房间邀请的二维码', ++ 'Scan to open this room': '扫码打开这个房间', ++ 'Anyone with the link can join while the room is open.': '只要房间还开着,拿到链接的人都能加入。', ++ 'Bot Social did not send an invite. Try again.': 'Bot Social 没有发来邀请,请重试。', } Object.assign(ZH, HOST_ZH) diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index fb4b5e26f..c93e14386 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -1317,7 +1317,7 @@ diff --git a/client.js b/client.js "The admin must be a member of the group": "管理员必须是群成员", "Unknown group chat": "找不到这个群聊", "Hand the admin role to another member instead of leaving the group without one": "请把管理员交给其他成员,不要让群聊没有管理员", -@@ -951,10 +951,38 @@ var HOST_ZH = { +@@ -951,10 +951,44 @@ var HOST_ZH = { "The model wrote nothing": "模型没有输出内容", "Write the entry to save.": "请写下要保存的内容。", "This DeepSeek Harness has no folder chooser": "这个 DeepSeek Harness 没有文件夹选择窗口", @@ -1350,7 +1350,13 @@ diff --git a/client.js b/client.js + "{name} is now a friend.": "{name} 现在成了你的朋友。", + "Declined {name}.": "已拒绝 {name}。", + "{what} failed: {why}": "{what} 失败:{why}", -+ "Your friend": "你的朋友" ++ "Your friend": "你的朋友", ++ // #3114 cut 25: the invite card in an open face-to-face room. ++ "Link ready": "链接已就绪", ++ "QR code for this room invite": "这个房间邀请的二维码", ++ "Scan to open this room": "扫码打开这个房间", ++ "Anyone with the link can join while the room is open.": "只要房间还开着,拿到链接的人都能加入。", ++ "Bot Social did not send an invite. Try again.": "Bot Social 没有发来邀请,请重试。" }; Object.assign(ZH, HOST_ZH); -var fill = (text, params) => params ? text.replace(/\{(\w+)\}/g, (match, name) => name in params ? String(params[name]) : match) : text; 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 58632ba1b..9718dfb97 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -2,15 +2,11 @@ "version": 1, "entries": [ "plugins/social/client.js: +{} more", - "plugins/social/client.js:Anyone with the link can join while the room is open.", "plugins/social/client.js:Chat paused", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", "plugins/social/client.js:In use in {} room{}: ", - "plugins/social/client.js:Link ready", "plugins/social/client.js:Past rooms", - "plugins/social/client.js:QR code for this room invite", "plugins/social/client.js:Remove this Bot from Friends' Bots and from your groups. This does not unfriend the owner.", - "plugins/social/client.js:Scan to open this room", "plugins/social/client.js:Social is not running: the plugin did not start. See Settings → Feedback.", "plugins/social/client.js:Social#1", "plugins/social/client.js:Social#2", diff --git a/patches/ds-bot/files/test/i18n-plugins.baseline.json b/patches/ds-bot/files/test/i18n-plugins.baseline.json index 45d91db2c..3189796ff 100644 --- a/patches/ds-bot/files/test/i18n-plugins.baseline.json +++ b/patches/ds-bot/files/test/i18n-plugins.baseline.json @@ -2,8 +2,7 @@ "version": 1, "entries": [ "plugins/social/client.js:Close", - "plugins/social/client.js:Copied#1", - "plugins/social/client.js:Copied#2", + "plugins/social/client.js:Copied", "plugins/social/client.js:Copy", "plugins/social/client.js:Your Bot Social handle", "plugins/timeline/client.js:Close", diff --git a/plugins/social/client.js b/plugins/social/client.js index 7aa6063e1..56efa1ffa 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -1150,7 +1150,7 @@ window.__ModuleLoader__.load({ const value = await call('social/face-invite', { roomId }) if (value?.unsupported) setInvite({ unsupported: true }) else if (value?.url) setInvite({ url: String(value.url), ticket: value.ticket, expiresAt: value.expiresAt }) - else setInvite({ error: 'Bot Social did not send an invite. Try again.' }) + else setInvite({ error: tr('Bot Social did not send an invite. Try again.') }) } catch (e) { setInvite({ error: errorText(e) }) } finally { setBusy(false) } @@ -1182,7 +1182,7 @@ window.__ModuleLoader__.load({ h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'face-invite-mint', disabled: !!busy || (!!invite?.url && live), onClick: mint, - }, invite?.url && live ? 'Link ready' : tr('Create link'))), + }, invite?.url && live ? tr('Link ready') : tr('Create link'))), invite?.unsupported ? h('div', { className: 'fs-hint', 'data-flybot': 'face-invite-unsupported', role: 'status' }, tr(INVITE_UNSUPPORTED)) : null, @@ -1196,13 +1196,13 @@ window.__ModuleLoader__.load({ ? h('div', { className: 'fs-invite-live', 'data-flybot': 'face-invite-live' }, h(QrImage, { text: invite.url, kind: 'face-invite-qr', at: invite.expiresAt || 'open', attrs: { 'data-url': invite.url }, - label: 'QR code for this room invite', hint: 'Scan to open this room', + label: tr('QR code for this room invite'), hint: tr('Scan to open this room'), }), h('div', { className: 'fs-invite-link' }, h('code', { className: 'fs-invite-url', 'data-flybot': 'face-invite-url' }, invite.url), - h('button', { type: 'button', className: 'fs-link', 'data-flybot': 'face-invite-copy', onClick: copy }, copied ? 'Copied' : tr('Copy link'))), + h('button', { type: 'button', className: 'fs-link', 'data-flybot': 'face-invite-copy', onClick: copy }, copied ? tr('Copied') : tr('Copy link'))), h('div', { className: 'fs-hint', 'data-flybot': 'face-invite-count' }, - invite.expiresAt ? countdownLine(countdown(invite.expiresAt)) : 'Anyone with the link can join while the room is open.'), + invite.expiresAt ? countdownLine(countdown(invite.expiresAt)) : tr('Anyone with the link can join while the room is open.')), h('button', { type: 'button', className: 'fs-link', 'data-flybot': 'face-invite-revoke', disabled: !!busy, onClick: revoke }, tr('Withdraw link'))) : null) } diff --git a/plugins/social/test/add-friend-i18n.test.js b/plugins/social/test/add-friend-i18n.test.js index 089db9dc9..939bd1f30 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], [13, 14, 55]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 14, 51]) // 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/face-invite-card-i18n.test.js b/plugins/social/test/face-invite-card-i18n.test.js new file mode 100644 index 000000000..5e54bd4b0 --- /dev/null +++ b/plugins/social/test/face-invite-card-i18n.test.js @@ -0,0 +1,107 @@ +// #3114 cut 25: the invite card inside an open face-to-face room — the `Link ready` button, the QR's +// name and hint, the `Copied` state, the no-deadline line and the error a mint with no link comes back +// with — drew English in a zh window. A zh window reads the dictionary's words, a host with no +// translator keeps today's English word for word, and the baselines lose these pins. +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 +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 room overview keeps five hook slots before its children: busy, note, tick, snapshot, dialog +// tick. The open branch then draws ConfirmLeave (ask), FaceAutoSendControl (on, busy, error) and +// FaceInviteCard (invite, busy, copied, tick). A setter records what the card would draw next, so a +// mint with no link can be read without a browser. +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) + const written = [] + let seed = 0 + const app = registered[0].factory(() => ({ + createElement: (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat(Infinity) }), + Fragment: 'F', useEffect() {}, useMemo: fn => fn(), useRef: value => ({ current: value }), + useState: (value) => { + const at = seed++ + return [at < states.length ? states[at] : value, next => written.push({ at, value: typeof next === 'function' ? next(at < states.length ? states[at] : value) : next })] + }, + })) + return { app, written } +} +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 textsOf = nodes => nodes.flatMap(node => (node.children ?? []).filter(child => typeof child === 'string')) +const byId = (nodes, id) => nodes.find(node => node.props?.['data-flybot'] === id) +const ROOM = { id: 'g1', origin: 'face-to-face', face: { roomId: 'frm_1', status: 'open' }, participants: [] } +const props = { room: ROOM, roster: { byId: {} } } +const inviteState = (invite = null) => ['', null, 0, null, 0, false, {}, '', '', invite, false, true, 0] +const open = (flybot, invite, more = {}) => { + const ui = loadApp(flybot, [...inviteState(invite), ...(more.states ?? [])]) + return { ...ui, nodes: walk(ui.app.FaceRoomOverview(props)) } +} +const LINK = { url: 'https://social.example/r/abc123', ticket: 'tkt_1' } + +test('#3114 cut 25: the room invite card speaks the window’s language', () => { + const { nodes } = open(zhWindow, LINK) + assert.ok(textsOf([byId(nodes, 'face-invite-mint')]).includes('链接已就绪'), 'the mint button is still "Link ready"') + assert.equal(nodes.find(node => node.props.className === 'fs-qr-svg')?.props['aria-label'], '这个房间邀请的二维码', 'the QR’s name is still English') + assert.ok(textsOf([byId(nodes, 'face-invite-qr-hint')]).includes('扫码打开这个房间'), 'the QR’s hint is still English') + assert.ok(textsOf([byId(nodes, 'face-invite-copy')]).includes('已复制'), 'the copied state is still "Copied"') + assert.ok(textsOf([byId(nodes, 'face-invite-count')]).includes('只要房间还开着,拿到链接的人都能加入。'), 'the no-deadline line is still English') +}) + +test('a mint with no link comes back in the window’s language', async () => { + const { nodes, written } = open(zhWindow, null) + byId(nodes, 'face-invite-mint').props.onClick() + for (let i = 0; i < 5; i += 1) await new Promise(resolve => setImmediate(resolve)) + assert.deepEqual(written.filter(item => item.at === 9).map(item => item.value?.error), ['Bot Social 没有发来邀请,请重试。']) +}) + +test('no translator keeps today’s English in the invite card', () => { + const { nodes } = open(bareWindow, LINK) + assert.ok(textsOf([byId(nodes, 'face-invite-mint')]).includes('Link ready')) + assert.equal(nodes.find(node => node.props.className === 'fs-qr-svg')?.props['aria-label'], 'QR code for this room invite') + assert.ok(textsOf([byId(nodes, 'face-invite-qr-hint')]).includes('Scan to open this room')) + assert.ok(textsOf([byId(nodes, 'face-invite-copy')]).includes('Copied')) + assert.ok(textsOf([byId(nodes, 'face-invite-count')]).includes('Anyone with the link can join while the room is open.')) +}) + +// The baselines may only shrink, and a pin leaves when its draw goes through `tr()`. +const MISSING_PINS = [ + 'Link ready', 'QR code for this room invite', + 'Scan to open this room', 'Anyone with the link can join while the room is open.', +] +const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries +test('the baselines lose these draws and the dictionary gains the keys', () => { + const pinned = entriesOf('i18n-missing-entries.baseline.json') + const still = MISSING_PINS.map(key => `plugins/social/client.js:${key}`).filter(id => pinned.includes(id)) + assert.deepEqual(still, [], `i18n-missing-entries still pins ${still.join(', ')}`) + const copies = entriesOf('i18n-plugins.baseline.json').filter(id => id.startsWith('plugins/social/client.js:Copied')) + assert.deepEqual(copies, ['plugins/social/client.js:Copied'], 'the bare-draw baseline keeps exactly one social Copied') + + // The English is today's English, verbatim: a key renamed on one side only is a red test. + const added = { + 'Link ready': '链接已就绪', + 'QR code for this room invite': '这个房间邀请的二维码', + 'Scan to open this room': '扫码打开这个房间', + 'Anyone with the link can join while the room is open.': '只要房间还开着,拿到链接的人都能加入。', + 'Bot Social did not send an invite. Try again.': 'Bot Social 没有发来邀请,请重试。', + } + for (const [key, value] of Object.entries(added)) assert.equal(zh[key], value, `the dictionary carries ${key}`) + assert.equal(zh.Copied, '已复制', 'the copied state reuses the entry it already has') +}) diff --git a/plugins/social/test/friend-settings-i18n.test.js b/plugins/social/test/friend-settings-i18n.test.js index dd51b65c0..ce72bc332 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, - ], [13, 14, 55]) + ], [12, 14, 51]) // 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/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js index 66208fad6..5cbf08403 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], [13, 14, 55]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [12, 14, 51]) // 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.