diff --git a/changelog.d/3219-face-waiting-room-zh.fixed.md b/changelog.d/3219-face-waiting-room-zh.fixed.md new file mode 100644 index 000000000..a15e4c88f --- /dev/null +++ b/changelog.d/3219-face-waiting-room-zh.fixed.md @@ -0,0 +1 @@ +A face-to-face waiting room now reads in the window's language: its number, QR hint, roster heading, Enter chat and Leave question no longer draw bare English in a Chinese window. diff --git a/core/client.js b/core/client.js index 19ab392e1..25731e984 100644 --- a/core/client.js +++ b/core/client.js @@ -284,6 +284,21 @@ var ZH = { "Revoke {who}? They lose this Bot in {n} room.": "撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。", "Revoke {who}? They lose this Bot in {n} rooms.": "撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。", "this person": "这个人", + // #3114 cut 21: the face-to-face waiting room — its number, QR hint, roster heading and alone + // line, Enter chat and the Leave question, which every window drew as bare English. + "Anyone with the number can still join.": "只要房间还开着,拿到号码的人都能加入。", + "The room is open. The number is no longer valid.": "房间已经开了,这个号码不再有效。", + "Who has joined": "谁已加入", + "Waiting for others to join…": "正在等其他人加入…", + "Enter chat": "进入聊天", + "Leave this room?": "离开这个房间?", + Leave: "离开", + Stay: "留下", + mine: "我的", + "Room number": "房间号码", + "Room number {code}": "房间号码 {code}", + "QR code for room number {code}": "房间号码 {code} 的二维码", + "Scan this with FlyBot to join": "用 FlyBot 扫描加入", "Share with a friend": "分享给朋友", "One click shares {name} with someone you already know. No invite link. They can decline; you can Revoke in People with access.": "一键把 {name} 分享给你已经认识的人,不需要邀请链接。对方可以拒绝,你也可以在「可访问的人」里撤销。", "Loading friends…": "正在加载朋友…", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 16ae5e104..cb613c248 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -251,6 +251,21 @@ const ZH = { 'Revoke {who}? They lose this Bot in {n} room.': '撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。', 'Revoke {who}? They lose this Bot in {n} rooms.': '撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。', 'this person': '这个人', + // #3114 cut 21: the face-to-face waiting room — its number, QR hint, roster heading and alone + // line, Enter chat and the Leave question, which every window drew as bare English. + 'Anyone with the number can still join.': '只要房间还开着,拿到号码的人都能加入。', + 'The room is open. The number is no longer valid.': '房间已经开了,这个号码不再有效。', + 'Who has joined': '谁已加入', + 'Waiting for others to join…': '正在等其他人加入…', + 'Enter chat': '进入聊天', + 'Leave this room?': '离开这个房间?', + Leave: '离开', + Stay: '留下', + mine: '我的', + 'Room number': '房间号码', + 'Room number {code}': '房间号码 {code}', + 'QR code for room number {code}': '房间号码 {code} 的二维码', + 'Scan this with FlyBot to join': '用 FlyBot 扫描加入', 'Share with a friend': '分享给朋友', 'One click shares {name} with someone you already know. No invite link. They can decline; you can Revoke in People with access.': '一键把 {name} 分享给你已经认识的人,不需要邀请链接。对方可以拒绝,你也可以在「可访问的人」里撤销。', 'Loading friends…': '正在加载朋友…', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index 8921cc238..71c8c7ace 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -4,7 +4,6 @@ "plugins/social/client.js: +{} more", "plugins/social/client.js:Accept an invite", "plugins/social/client.js:Anyone with the link can join while the room is open.", - "plugins/social/client.js:Anyone with the number can still join.", "plugins/social/client.js:Bot Social could not look up that link right now. Try again.", "plugins/social/client.js:Chat paused", "plugins/social/client.js:Choose which of your Bots join.", @@ -16,8 +15,6 @@ "plugins/social/client.js:Don't ask each time.#1", "plugins/social/client.js:Don't ask each time.#2", "plugins/social/client.js:Enter a 6-digit number.", - "plugins/social/client.js:Enter chat#1", - "plugins/social/client.js:Enter chat#2", "plugins/social/client.js:FlyBot cannot use the camera. Allow the camera for this page, or type the 6-digit number instead.", "plugins/social/client.js:In use in {} room{}: ", "plugins/social/client.js:Invite a friend", @@ -30,9 +27,6 @@ "plugins/social/client.js:Joined {}'s invite, but their Bot hasn't loaded yet. It shows in your list when it does; if not, accept the link again.{}", "plugins/social/client.js:Joining with that link…#1", "plugins/social/client.js:Joining with that link…#2", - "plugins/social/client.js:Leave this room?", - "plugins/social/client.js:Leave#1", - "plugins/social/client.js:Leave#2", "plugins/social/client.js:Link ready", "plugins/social/client.js:Loading your Bots…", "plugins/social/client.js:Looking up that room…#1", @@ -47,8 +41,6 @@ "plugins/social/client.js:Remove this Bot#2", "plugins/social/client.js:Removing…", "plugins/social/client.js:Request sent to {}. They show up here once they accept.", - "plugins/social/client.js:Room number", - "plugins/social/client.js:Scan this with FlyBot to join", "plugins/social/client.js:Scan to open this room", "plugins/social/client.js:Scanned a group link.", "plugins/social/client.js:Scanned an invite link.", @@ -56,7 +48,6 @@ "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", - "plugins/social/client.js:Stay", "plugins/social/client.js:Talk through ", "plugins/social/client.js:Talks for you. Not shared: your friend can't use it unless you invite them to it.", "plugins/social/client.js:That is not a FlyBot room code. Ask for the 6-digit number instead.", @@ -69,7 +60,6 @@ "plugins/social/client.js:That room cannot take guests right now.", "plugins/social/client.js:The FlyBot host did not answer (HTTP {}). Reload the page; if this keeps happening, restart FlyBot web.", "plugins/social/client.js:The camera stopped before it read a code. Type the 6-digit number instead.", - "plugins/social/client.js:The room is open. The number is no longer valid.", "plugins/social/client.js:This FlyBot has no Bot Social identity yet.", "plugins/social/client.js:This browser cannot scan codes. Type the 6-digit number instead.", "plugins/social/client.js:This browser cannot use a camera here. Type the 6-digit number instead.", @@ -77,20 +67,13 @@ "plugins/social/client.js:This invite was already used. Ask your friend for a new one.", "plugins/social/client.js:This room only: ", "plugins/social/client.js:Too many tries for now. Wait a minute and try again.", - "plugins/social/client.js:Waiting for others to join…#1", - "plugins/social/client.js:Waiting for others to join…#2", "plugins/social/client.js:Which of your Bots talks", "plugins/social/client.js:Which of your Bots to share", - "plugins/social/client.js:Who has joined#1", - "plugins/social/client.js:Who has joined#2", "plugins/social/client.js:You already joined with that link using other Bots. Leave the group first to join with different ones.", "plugins/social/client.js:Your friend gets this Bot only.", "plugins/social/client.js:Your own Bots stay shared. {} can share it again.", - "plugins/social/client.js:mine#1", - "plugins/social/client.js:mine#2", "plugins/social/client.js:the group", "plugins/social/client.js:the room", - "plugins/social/client.js:{} (you)", "plugins/social/client.js:{} is now a friend.", "plugins/social/client.js:{} shared {} with you.{}", "plugins/social/client.js:{} stays a friend: still shared through {}.", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index 62e6b87d0..f034dbc7b 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -9,9 +9,7 @@ "plugins/social/client.js:Invite grants {} only.", "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", "plugins/social/client.js:Invite link for {}", - "plugins/social/client.js:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", - "plugins/social/client.js:Room number {}", "plugins/social/client.js:Scanned {}.", "plugins/social/client.js:Scanned {}. Pick a Bot to join.", "plugins/social/client.js:Waiting for {} to let you in. If the group does not appear, press Join group to ask again.", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 6da945192..46b3f611a 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,132 @@ const ZH = { +@@ -41,22 +41,147 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -974,6 +974,21 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'Revoke {who}? They lose this Bot in {n} room.': '撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。', + 'Revoke {who}? They lose this Bot in {n} rooms.': '撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。', + 'this person': '这个人', ++ // #3114 cut 21: the face-to-face waiting room — its number, QR hint, roster heading and alone ++ // line, Enter chat and the Leave question, which every window drew as bare English. ++ 'Anyone with the number can still join.': '只要房间还开着,拿到号码的人都能加入。', ++ 'The room is open. The number is no longer valid.': '房间已经开了,这个号码不再有效。', ++ 'Who has joined': '谁已加入', ++ 'Waiting for others to join…': '正在等其他人加入…', ++ 'Enter chat': '进入聊天', ++ 'Leave this room?': '离开这个房间?', ++ Leave: '离开', ++ Stay: '留下', ++ mine: '我的', ++ 'Room number': '房间号码', ++ 'Room number {code}': '房间号码 {code}', ++ 'QR code for room number {code}': '房间号码 {code} 的二维码', ++ 'Scan this with FlyBot to join': '用 FlyBot 扫描加入', + 'Share with a friend': '分享给朋友', + 'One click shares {name} with someone you already know. No invite link. They can decline; you can Revoke in People with access.': '一键把 {name} 分享给你已经认识的人,不需要邀请链接。对方可以拒绝,你也可以在「可访问的人」里撤销。', + 'Loading friends…': '正在加载朋友…', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 676869613..ccbb60544 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,131 @@ var ZH = { +@@ -78,21 +78,146 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -238,6 +238,21 @@ diff --git a/client.js b/client.js + "Revoke {who}? They lose this Bot in {n} room.": "撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。", + "Revoke {who}? They lose this Bot in {n} rooms.": "撤销 {who} 的授权?对方将在 {n} 个房间里失去这个 Bot。", + "this person": "这个人", ++ // #3114 cut 21: the face-to-face waiting room — its number, QR hint, roster heading and alone ++ // line, Enter chat and the Leave question, which every window drew as bare English. ++ "Anyone with the number can still join.": "只要房间还开着,拿到号码的人都能加入。", ++ "The room is open. The number is no longer valid.": "房间已经开了,这个号码不再有效。", ++ "Who has joined": "谁已加入", ++ "Waiting for others to join…": "正在等其他人加入…", ++ "Enter chat": "进入聊天", ++ "Leave this room?": "离开这个房间?", ++ Leave: "离开", ++ Stay: "留下", ++ mine: "我的", ++ "Room number": "房间号码", ++ "Room number {code}": "房间号码 {code}", ++ "QR code for room number {code}": "房间号码 {code} 的二维码", ++ "Scan this with FlyBot to join": "用 FlyBot 扫描加入", + "Share with a friend": "分享给朋友", + "One click shares {name} with someone you already know. No invite link. They can decline; you can Revoke in People with access.": "一键把 {name} 分享给你已经认识的人,不需要邀请链接。对方可以拒绝,你也可以在「可访问的人」里撤销。", + "Loading friends…": "正在加载朋友…", 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 8921cc238..71c8c7ace 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -4,7 +4,6 @@ "plugins/social/client.js: +{} more", "plugins/social/client.js:Accept an invite", "plugins/social/client.js:Anyone with the link can join while the room is open.", - "plugins/social/client.js:Anyone with the number can still join.", "plugins/social/client.js:Bot Social could not look up that link right now. Try again.", "plugins/social/client.js:Chat paused", "plugins/social/client.js:Choose which of your Bots join.", @@ -16,8 +15,6 @@ "plugins/social/client.js:Don't ask each time.#1", "plugins/social/client.js:Don't ask each time.#2", "plugins/social/client.js:Enter a 6-digit number.", - "plugins/social/client.js:Enter chat#1", - "plugins/social/client.js:Enter chat#2", "plugins/social/client.js:FlyBot cannot use the camera. Allow the camera for this page, or type the 6-digit number instead.", "plugins/social/client.js:In use in {} room{}: ", "plugins/social/client.js:Invite a friend", @@ -30,9 +27,6 @@ "plugins/social/client.js:Joined {}'s invite, but their Bot hasn't loaded yet. It shows in your list when it does; if not, accept the link again.{}", "plugins/social/client.js:Joining with that link…#1", "plugins/social/client.js:Joining with that link…#2", - "plugins/social/client.js:Leave this room?", - "plugins/social/client.js:Leave#1", - "plugins/social/client.js:Leave#2", "plugins/social/client.js:Link ready", "plugins/social/client.js:Loading your Bots…", "plugins/social/client.js:Looking up that room…#1", @@ -47,8 +41,6 @@ "plugins/social/client.js:Remove this Bot#2", "plugins/social/client.js:Removing…", "plugins/social/client.js:Request sent to {}. They show up here once they accept.", - "plugins/social/client.js:Room number", - "plugins/social/client.js:Scan this with FlyBot to join", "plugins/social/client.js:Scan to open this room", "plugins/social/client.js:Scanned a group link.", "plugins/social/client.js:Scanned an invite link.", @@ -56,7 +48,6 @@ "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", - "plugins/social/client.js:Stay", "plugins/social/client.js:Talk through ", "plugins/social/client.js:Talks for you. Not shared: your friend can't use it unless you invite them to it.", "plugins/social/client.js:That is not a FlyBot room code. Ask for the 6-digit number instead.", @@ -69,7 +60,6 @@ "plugins/social/client.js:That room cannot take guests right now.", "plugins/social/client.js:The FlyBot host did not answer (HTTP {}). Reload the page; if this keeps happening, restart FlyBot web.", "plugins/social/client.js:The camera stopped before it read a code. Type the 6-digit number instead.", - "plugins/social/client.js:The room is open. The number is no longer valid.", "plugins/social/client.js:This FlyBot has no Bot Social identity yet.", "plugins/social/client.js:This browser cannot scan codes. Type the 6-digit number instead.", "plugins/social/client.js:This browser cannot use a camera here. Type the 6-digit number instead.", @@ -77,20 +67,13 @@ "plugins/social/client.js:This invite was already used. Ask your friend for a new one.", "plugins/social/client.js:This room only: ", "plugins/social/client.js:Too many tries for now. Wait a minute and try again.", - "plugins/social/client.js:Waiting for others to join…#1", - "plugins/social/client.js:Waiting for others to join…#2", "plugins/social/client.js:Which of your Bots talks", "plugins/social/client.js:Which of your Bots to share", - "plugins/social/client.js:Who has joined#1", - "plugins/social/client.js:Who has joined#2", "plugins/social/client.js:You already joined with that link using other Bots. Leave the group first to join with different ones.", "plugins/social/client.js:Your friend gets this Bot only.", "plugins/social/client.js:Your own Bots stay shared. {} can share it again.", - "plugins/social/client.js:mine#1", - "plugins/social/client.js:mine#2", "plugins/social/client.js:the group", "plugins/social/client.js:the room", - "plugins/social/client.js:{} (you)", "plugins/social/client.js:{} is now a friend.", "plugins/social/client.js:{} shared {} with you.{}", "plugins/social/client.js:{} stays a friend: still shared through {}.", 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 62e6b87d0..f034dbc7b 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -9,9 +9,7 @@ "plugins/social/client.js:Invite grants {} only.", "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", "plugins/social/client.js:Invite link for {}", - "plugins/social/client.js:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", - "plugins/social/client.js:Room number {}", "plugins/social/client.js:Scanned {}.", "plugins/social/client.js:Scanned {}. Pick a Bot to join.", "plugins/social/client.js:Waiting for {} to let you in. If the group does not appear, press Join group to ask again.", diff --git a/plugins/social/client.js b/plugins/social/client.js index aaa04d9df..0f5bea7a8 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -468,7 +468,7 @@ window.__ModuleLoader__.load({ const mark = h('span', { className: 'fs-tile-mark' }, h(FaceAvatar, { bot, size: 48 }), mine - ? h('span', { className: 'fs-tile-mine', 'data-flybot': 'face-mine', title: 'mine', 'aria-label': 'mine' }) + ? h('span', { className: 'fs-tile-mine', 'data-flybot': 'face-mine', title: tr('mine'), 'aria-label': tr('mine') }) : null, pick && selected ? h('span', { className: 'fs-tile-check', 'data-flybot': 'face-pick-check', 'aria-hidden': true }, '✓') @@ -533,7 +533,7 @@ window.__ModuleLoader__.load({ function FacePersonTile({ person, look } = {}) { const bots = person.members.map(member => faceTileParts(member).name) const who = person.name || (person.mine ? 'You' : 'Someone') - const label = person.mine && person.name ? `${person.name} (you)` : who + const label = person.mine && person.name ? tr('{name} (you)', { name: person.name }) : who const handles = person.members.map(faceMemberHandle).filter(Boolean) return h('li', { className: 'fs-tile', @@ -545,7 +545,7 @@ window.__ModuleLoader__.load({ }, h('span', { className: 'fs-tile-mark' }, h(FaceAvatar, { bot: look(person.members[0]), size: 48 }), - person.mine ? h('span', { className: 'fs-tile-mine', 'data-flybot': 'face-mine', title: 'mine', 'aria-label': 'mine' }) : null), + person.mine ? h('span', { className: 'fs-tile-mine', 'data-flybot': 'face-mine', title: tr('mine'), 'aria-label': tr('mine') }) : null), h('span', { className: 'fs-tile-name', 'data-flybot': 'face-owner', title: label }, label), h('span', { className: 'fs-tile-sub', 'data-flybot': 'face-bot', title: bots.join(', ') }, bots.join(', '))) } @@ -570,13 +570,13 @@ window.__ModuleLoader__.load({ function ConfirmLeave({ busy, onLeave, flybot = 'face-leave', size = 'fs-btn fs-btn-sm', beside = null } = {}) { const [ask, setAsk] = useState(false) if (!ask) { - const leave = h('button', { type: 'button', className: size, 'data-flybot': flybot, disabled: !!busy, onClick: () => setAsk(true) }, 'Leave') + const leave = h('button', { type: 'button', className: size, 'data-flybot': flybot, disabled: !!busy, onClick: () => setAsk(true) }, tr('Leave')) return beside ? h(Fragment, null, leave, beside) : leave } return h('span', { className: 'fs-leave-ask', 'data-flybot': 'face-leave-confirm' }, - h('span', { className: 'fs-hint' }, 'Leave this room?'), - h('button', { type: 'button', className: size, 'data-flybot': 'face-leave-yes', disabled: !!busy, onClick: () => { setAsk(false); onLeave?.() } }, 'Leave'), - h('button', { type: 'button', className: size, 'data-flybot': 'face-leave-no', onClick: () => setAsk(false) }, 'Stay')) + h('span', { className: 'fs-hint' }, tr('Leave this room?')), + h('button', { type: 'button', className: size, 'data-flybot': 'face-leave-yes', disabled: !!busy, onClick: () => { setAsk(false); onLeave?.() } }, tr('Leave')), + h('button', { type: 'button', className: size, 'data-flybot': 'face-leave-no', onClick: () => setAsk(false) }, tr('Stay'))) } // Auto-send is one switch per Bot of mine in the room (#457, owner decision: option a), each @@ -1128,8 +1128,8 @@ window.__ModuleLoader__.load({ if (!digits) return null return h(QrImage, { text: faceQrText(digits), kind: 'face-qr', at, offsetMs, - attrs: { 'data-code': digits }, label: `QR code for room number ${digits}`, - hint: 'Scan this with FlyBot to join', + attrs: { 'data-code': digits }, label: tr('QR code for room number {code}', { code: digits }), + hint: tr('Scan this with FlyBot to join'), }) } // An invite into a room that already exists: the QR is the link, so a phone camera opens it and @@ -1346,8 +1346,8 @@ window.__ModuleLoader__.load({ function FaceWaitCode({ code, qrAt, qrOffsetMs } = {}) { const digits = String(code || '').replace(/\D/g, '').slice(0, 6) if (digits.length !== 6) return null - return h('div', { className: 'fs-wait-code', 'data-flybot': 'face-wait-code', 'aria-label': `Room number ${digits}` }, - h('div', { className: 'fs-wait-code-label' }, 'Room number'), + return h('div', { className: 'fs-wait-code', 'data-flybot': 'face-wait-code', 'aria-label': tr('Room number {code}', { code: digits }) }, + h('div', { className: 'fs-wait-code-label' }, tr('Room number')), h('div', { className: 'fs-wait-code-digits', 'data-flybot': 'face-wait-code-digits' }, digits), h(FaceQr, { code: digits, at: qrAt, offsetMs: qrOffsetMs })) } @@ -1867,16 +1867,16 @@ window.__ModuleLoader__.load({ qrOffsetMs: room.clockOffsetMs, }), h('div', { className: 'fs-hint fs-wait-count', 'data-flybot': 'face-wait-count', 'data-tick': tick }, candidate - ? (room.expiresAt ? countdownLine(countdown(room.expiresAt, room.clockOffsetMs)) : 'Anyone with the number can still join.') - : 'The room is open. The number is no longer valid.'), + ? (room.expiresAt ? countdownLine(countdown(room.expiresAt, room.clockOffsetMs)) : tr('Anyone with the number can still join.')) + : tr('The room is open. The number is no longer valid.')), h('div', { className: 'fs-wait-body' }, - h('ul', { className: 'fs-tiles fs-wait-roster', 'data-flybot': 'face-wait-roster', 'aria-label': 'Who has joined' }, + h('ul', { className: 'fs-tiles fs-wait-roster', 'data-flybot': 'face-wait-roster', 'aria-label': tr('Who has joined') }, facePeople(members, member => memberIsMine(member, bots, room)).map(person => h(FacePersonTile, { key: person.key, person, look: member => faceLook({ roster, remoteChats, bots, member, mine: room.mineBots }), }))), - othersIn(members, member => memberIsMine(member, bots, room)) ? null : h('div', { className: 'fs-hint', 'data-flybot': 'face-wait-alone' }, 'Waiting for others to join…'), + othersIn(members, member => memberIsMine(member, bots, room)) ? null : h('div', { className: 'fs-hint', 'data-flybot': 'face-wait-alone' }, tr('Waiting for others to join…')), failures.length ? h('div', { className: 'fs-status', 'data-tone': 'error', 'data-flybot': 'face-join-fail', role: 'status' }, failures.map(item => `${item.name}: ${item.text}`).join(' ')) : null, status ? h('div', { className: 'fs-status', 'data-tone': status.tone, role: 'status' }, status.text) : null), @@ -1886,7 +1886,7 @@ window.__ModuleLoader__.load({ beside: h('button', { type: 'button', className: 'fs-btn fs-btn-primary', 'data-flybot': 'face-enter', disabled: !!busy || !room.roomId, onClick: enter, - }, 'Enter chat'), + }, tr('Enter chat')), }))) : h('form', { onSubmit: join, 'data-flybot': 'face-join' }, h('div', { className: 'fs-hint', 'data-flybot': 'face-join-about' }, tr(starting ? START_FACE_ABOUT : JOIN_OR_CREATE_ABOUT)), h('ul', { className: 'fs-tiles fs-pick', 'data-flybot': 'face-pick', 'aria-label': 'Your Bots' }, @@ -3151,8 +3151,8 @@ window.__ModuleLoader__.load({ qrOffsetMs: snapshot?.clockOffsetMs, }), h('div', { className: 'fs-hint fs-wait-count', 'data-tick': tick, 'data-flybot': 'face-wait-count' }, - expiresAt ? countdownLine(countdown(expiresAt, snapshot?.clockOffsetMs)) : 'Anyone with the number can still join.'), - h('ul', { className: 'fs-tiles fs-wait-roster', 'data-flybot': 'face-wait-roster', 'aria-label': 'Who has joined' }, + expiresAt ? countdownLine(countdown(expiresAt, snapshot?.clockOffsetMs)) : tr('Anyone with the number can still join.')), + h('ul', { className: 'fs-tiles fs-wait-roster', 'data-flybot': 'face-wait-roster', 'aria-label': tr('Who has joined') }, facePeople(members, mineMember).map(person => h(FacePersonTile, { key: person.key, person, @@ -3161,7 +3161,7 @@ window.__ModuleLoader__.load({ ? faceLook({ roster, local: roster.byId[member.id] }) : faceLook({ roster, member })), }))), - othersIn(members, mineMember) ? null : h('div', { className: 'fs-hint', 'data-flybot': 'face-wait-alone' }, 'Waiting for others to join…'), + othersIn(members, mineMember) ? null : h('div', { className: 'fs-hint', 'data-flybot': 'face-wait-alone' }, tr('Waiting for others to join…')), locked ? null : h('div', { className: 'fs-wait-foot', 'data-flybot': 'face-wait-foot' }, h(ConfirmLeave, { busy, @@ -3176,7 +3176,7 @@ window.__ModuleLoader__.load({ await call('social/face-start', { roomId: room.id, faceRoomId: face?.roomId }) if (room.id && typeof actions?.openSession === 'function') actions.openSession(room.id) }), - }, 'Enter chat'), + }, tr('Enter chat')), })), note ? h('div', { className: 'fs-status', 'data-tone': note.tone }, note.text) : null) } diff --git a/plugins/social/test/face-waiting-room-i18n.test.js b/plugins/social/test/face-waiting-room-i18n.test.js new file mode 100644 index 000000000..9fa5814a2 --- /dev/null +++ b/plugins/social/test/face-waiting-room-i18n.test.js @@ -0,0 +1,140 @@ +// #3114 cut 21: the Face-to-face waiting room — the dialog's `waiting` step and the room +// overview's candidate card — drew its number, QR hint, roster heading, alone line, Enter chat, +// Leave question and mine badges as bare English, while the rest of the panel followed the +// window's language. `plugins/social/client.js` already carries `tr()`, so this pins the block: a +// zh window reads the dictionary's words, a host with no translator keeps today's English word for +// word, and the two i18n baselines lose the 19 pins. The copy is read out of the rendered tree. +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, and a host with no translator at all: `tr()` then hands back the +// English it was given, so the two windows differ only in the copy the panel draws. +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 registering its factory on `window`, and the plugin reads +// `__flybot__` off the global object at render time — so the sandbox is that global object. The +// `useState` list is how a screen a click reaches (the waiting step) is drawn without a browser. +function loadApp(flybot) { + const registered = [] + const sandbox = { window: { __ModuleLoader__: { load: entry => registered.push(entry) } }, console, setTimeout, clearTimeout } + sandbox.globalThis = sandbox + sandbox.__flybot__ = flybot + runInNewContext(readFileSync(new URL('../client.js', import.meta.url), 'utf8'), sandbox) + const ui = { queue: [], at: 0, app: null } + ui.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(), useCallback: fn => fn(), + useState: () => [ui.queue[ui.at++], () => {}], + })) + return ui +} +// A component element is a function in `type`: it has to be called to see what it draws. +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 draw = (ui, name, props = {}, queue = []) => { ui.queue = queue; ui.at = 0; return walk(ui.app[name](props)) } +const textsOf = nodes => nodes.flatMap(node => (node.children ?? []).filter(child => typeof child === 'string')) +const textAt = (nodes, id) => (nodes.find(node => node.props?.['data-flybot'] === id)?.children ?? []).filter(child => typeof child === 'string').join('') +const propAt = (nodes, id, prop) => nodes.find(node => node.props?.['data-flybot'] === id)?.props?.[prop] +const buttons = nodes => nodes.filter(node => node.type === 'button').map(node => node.children.join('')) +// One sentence as a person reads it: the dictionary's answer, or undefined while it is English. +function says(nodes, english) { + const hit = textsOf(nodes).find(text => text === zh[english]) + assert.ok(hit, `expected ${hit} (${english}), saw ${JSON.stringify(textsOf(nodes))}`) +} +// The waiting step after a start or a join: one room of mine, six digits, nobody else in it yet. The dialog keeps its state in eleven hook slots, answered in this order by the stub's list. +const ROOM = { + roomId: 'local1', faceRoomId: 'fr1', joinCode: '482913', status: 'open', mineHandles: ['@chief.home'], + members: [{ id: 'b1', remote: false, handle: '@chief.home', name: 'Chief', ownerName: 'Ann' }], +} +// A candidate room is the same screen with a deadline, so it draws the QR next to the number. +const CANDIDATE = { ...ROOM, status: 'candidate', expiresAt: new Date(Date.now() + 90000).toISOString() } +const BOT = { id: 'b1', name: 'Chief', handle: '@chief.home', isMain: true } +const dialog = (flybot, room = ROOM) => draw(loadApp(flybot), 'FaceToFaceGroup', { mode: 'join', roster: { byId: {}, readOnly: '' }, remoteChats: [] }, + ['waiting', [BOT], ['b1'], '482913', false, null, [], room, 0, null, { link: '', status: null }]) +const leave = (flybot, ask) => draw(loadApp(flybot), 'ConfirmLeave', {}, [ask]) +test('#3114 cut 21: the waiting room speaks the window’s language', () => { + const nodes = dialog(zhWindow) + says(nodes, 'The room is open. The number is no longer valid.') + says(nodes, 'Waiting for others to join…') + says(nodes, 'Enter chat') + assert.equal(propAt(nodes, 'face-wait-roster', 'aria-label'), '谁已加入', `the roster’s name: saw ${propAt(nodes, 'face-wait-roster', 'aria-label')}`) + // The badge and the one-name form are the two entries this cut reuses, not adds. + assert.equal(propAt(nodes, 'face-mine', 'title'), '我的', 'the mine badge follows the window too') + assert.equal(propAt(nodes, 'face-owner', 'title'), 'Ann(你)', 'the person tile reads {name} (you) through the dictionary') +}) + +test('#3114 cut 21: the room number and its QR speak the window’s language', () => { + const nodes = dialog(zhWindow, CANDIDATE) + assert.equal(propAt(nodes, 'face-wait-code', 'aria-label'), '房间号码 482913', 'the number’s accessible name follows the window') + assert.ok(textsOf(nodes).includes('房间号码'), `expected 房间号码, saw ${JSON.stringify(textsOf(nodes))}`) + assert.equal(nodes.find(node => node.type === 'svg')?.props?.['aria-label'], '房间号码 482913 的二维码', 'the QR’s accessible name follows it too') + assert.equal(textAt(nodes, 'face-qr-hint'), '用 FlyBot 扫描加入', 'the hint under the QR follows the window too') +}) + +test('#3114 cut 21: Leave asks in the window’s language', () => { + const asked = leave(zhWindow, true) + says(asked, 'Leave this room?') + assert.deepEqual(buttons(asked), ['离开', '留下'], 'both answers follow the window') + assert.deepEqual(buttons(leave(zhWindow, false)), ['离开'], 'and so does the one button before the question') +}) + +test('#3114 cut 21: no translator keeps today\'s English in the waiting room', () => { + const nodes = dialog(bareWindow) + assert.equal(textAt(nodes, 'face-wait-count'), 'The room is open. The number is no longer valid.') + assert.deepEqual([propAt(nodes, 'face-wait-roster', 'aria-label'), propAt(nodes, 'face-mine', 'title'), propAt(nodes, 'face-owner', 'title')], ['Who has joined', 'mine', 'Ann (you)']) + assert.deepEqual(textsOf(nodes).filter(text => ['Waiting for others to join…', 'Enter chat'].includes(text)), ['Waiting for others to join…', 'Enter chat']) + const candidate = dialog(bareWindow, CANDIDATE) + assert.deepEqual([propAt(candidate, 'face-wait-code', 'aria-label'), candidate.find(node => node.type === 'svg')?.props?.['aria-label'], textAt(candidate, 'face-qr-hint'), ...textsOf(candidate).filter(text => text === 'Room number')], + ['Room number 482913', 'QR code for room number 482913', 'Scan this with FlyBot to join', 'Room number']) + const asked = leave(bareWindow, true) + assert.deepEqual([asked.filter(node => node.props?.className === 'fs-hint').map(node => node.children.join('')).join('|'), buttons(asked).join('|')], ['Leave this room?', 'Leave|Stay']) +}) +// The baselines may only shrink, and a pin leaves when its draw goes through `tr()`. +const MISSING_PINS = [ + 'Anyone with the number can still join.', 'The room is open. The number is no longer valid.', + 'Who has joined#1', 'Who has joined#2', 'Waiting for others to join…#1', 'Waiting for others to join…#2', + 'Enter chat#1', 'Enter chat#2', 'Leave this room?', 'Leave#1', 'Leave#2', 'Stay', + 'mine#1', 'mine#2', 'Room number', 'Scan this with FlyBot to join', '{} (you)', +] +const TEMPLATE_PINS = ['Room number {}', 'QR code for room number {}'] +const baselineEntries = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries +test('#3114 cut 21: the baselines lose these draws and the dictionary gains the keys', () => { + const pinned = baselineEntries('i18n-missing-entries.baseline.json') + const missing = MISSING_PINS.map(key => `plugins/social/client.js:${key}`).filter(id => pinned.includes(id)) + assert.deepEqual(missing, [], `i18n-missing-entries still pins ${missing.join(', ')}`) + const templates = TEMPLATE_PINS.map(key => `plugins/social/client.js:${key}`).filter(id => baselineEntries('i18n-template-draws.baseline.json').includes(id)) + assert.deepEqual(templates, [], `i18n-template-draws still pins ${templates.join(', ')}`) + + // The English is today's English, verbatim: a key renamed on one side only is a red test. + const added = { + 'Anyone with the number can still join.': '只要房间还开着,拿到号码的人都能加入。', + 'The room is open. The number is no longer valid.': '房间已经开了,这个号码不再有效。', + 'Who has joined': '谁已加入', + 'Waiting for others to join…': '正在等其他人加入…', + 'Enter chat': '进入聊天', + 'Leave this room?': '离开这个房间?', + Leave: '离开', + Stay: '留下', + mine: '我的', + 'Room number': '房间号码', + 'Room number {code}': '房间号码 {code}', + 'QR code for room number {code}': '房间号码 {code} 的二维码', + 'Scan this with FlyBot to join': '用 FlyBot 扫描加入', + } + for (const [key, value] of Object.entries(added)) assert.equal(zh[key], value, `the dictionary carries ${key}`) + assert.equal(zh['{name} (you)'], '{name}(你)', 'the one-name form is reused, never added twice') +}) diff --git a/plugins/social/test/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js index 2b0e5c9a4..9dc0af583 100644 --- a/plugins/social/test/sharing-page-i18n.test.js +++ b/plugins/social/test/sharing-page-i18n.test.js @@ -143,9 +143,9 @@ test('#3114 cut 20: the three baselines lose these draws', () => { 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 two baselines shrink by exactly these draws and nothing else does: the totals are the - // ratchet's numbers (16 / 27 / 132), and the third baseline is untouched. - assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [16, 27, 132]) + // The two baselines shrink by exactly these draws and nothing else does: the third baseline is + // untouched at 16, and a later cut that moves the other two totals 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], [16, 25, 115]) // 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.