Skip to content
Merged
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
1 change: 1 addition & 0 deletions changelog.d/3114-face-invite-card-i18n.fixed.md
Original file line number Diff line number Diff line change
@@ -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)).
8 changes: 7 additions & 1 deletion core/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions core/src/client/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 0 additions & 4 deletions core/test/i18n-missing-entries.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions core/test/i18n-plugins.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion patches/ds-bot/0001-core-fixes.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 不能列出文件夹',
Expand Down Expand Up @@ -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)

Expand Down
10 changes: 8 additions & 2 deletions patches/ds-bot/0008-client-bundle.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 没有文件夹选择窗口",
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions patches/ds-bot/files/test/i18n-missing-entries.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 1 addition & 2 deletions patches/ds-bot/files/test/i18n-plugins.baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions plugins/social/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@
function qrRsGenerator(degree) {
let poly = [1]
for (let i = 0; i < degree; i += 1) {
const next = new Array(poly.length + 1).fill(0)

Check warning on line 723 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let j = 0; j < poly.length; j += 1) {
next[j] ^= poly[j]
next[j + 1] ^= qrMul(poly[j], QR_GF_EXP[i])
Expand All @@ -731,7 +731,7 @@
}
function qrRsRemainder(bytes, degree) {
const gen = qrRsGenerator(degree)
const res = new Array(bytes.length + degree).fill(0)

Check warning on line 734 in plugins/social/client.js

View workflow job for this annotation

GitHub Actions / plugins (social)

unicorn(no-new-array)

Do not use `new Array(singleArgument)`.
for (let i = 0; i < bytes.length; i += 1) res[i] = bytes[i]
for (let i = 0; i < bytes.length; i += 1) {
const factor = res[i]
Expand Down Expand Up @@ -1150,7 +1150,7 @@
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) }
Expand Down Expand Up @@ -1182,7 +1182,7 @@
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,
Expand All @@ -1196,13 +1196,13 @@
? 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)
}
Expand Down
2 changes: 1 addition & 1 deletion plugins/social/test/add-friend-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
107 changes: 107 additions & 0 deletions plugins/social/test/face-invite-card-i18n.test.js
Original file line number Diff line number Diff line change
@@ -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')
})
2 changes: 1 addition & 1 deletion plugins/social/test/friend-settings-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'], '你的朋友')
})
2 changes: 1 addition & 1 deletion plugins/social/test/sharing-page-i18n.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading