diff --git a/changelog.d/3114-friend-settings-zh.changed.md b/changelog.d/3114-friend-settings-zh.changed.md new file mode 100644 index 000000000..8da2c925d --- /dev/null +++ b/changelog.d/3114-friend-settings-zh.changed.md @@ -0,0 +1 @@ +A friend's Bot settings now read in the window's language: its Auto-send box and hint, the Remove this Bot link with its busy label and tooltip, and the inline remove question no longer draw bare English in a Chinese window ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index 1f57b0db5..681ee8b0f 100644 --- a/core/client.js +++ b/core/client.js @@ -309,6 +309,17 @@ var ZH = { "That Bot was removed from that home.": "那个 Bot 已从对方那里移除。", "Messages waiting for your approval": "等你批准的消息", "Waiting for approval": "等待批准", + // #3114 cut 23: a friend's Bot settings card — its Auto-send box and hint, the Remove this Bot + // link with its busy label and tooltip, and the inline remove question that ends on the roster. + "Auto-send my Bots' replies to {who}": "我的 Bot 发给 {who} 的回复自动发送", + "Your Bots' replies to {who} go out without asking you first. What you type is not affected.": "你的 Bot 发给 {who} 的回复不再先问你。你输入的内容不受影响。", + "Remove this Bot": "移除这个 Bot", + "Removing…": "正在移除…", + "Remove this Bot from your list and from your groups. This does not unfriend the owner.": "把这个 Bot 从你的列表和群聊中移除。这不会解除与主人的好友关系。", + "Remove {bot} from your list? {note}": "把 {bot} 从你的列表中移除吗?{note}", + "{who} stays a friend: still shared through {bots}.": "{who} 仍是好友:仍通过 {bots} 共享。", + "Your own Bots stay shared. {who} can share it again.": "你自己的 Bot 仍然保持共享。{who} 可以再次分享它。", + "Don't ask each time.": "不要每次都问。", // #3032: the four approval-card controls that were still drawn as bare English. "Waiting for the owner's approval": "等待 owner 批准", "Auto-send from now on": "以后自动发送", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index c060d722b..579e3c962 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -276,6 +276,17 @@ const ZH = { 'That Bot was removed from that home.': '那个 Bot 已从对方那里移除。', 'Messages waiting for your approval': '等你批准的消息', 'Waiting for approval': '等待批准', + // #3114 cut 23: a friend's Bot settings card — its Auto-send box and hint, the Remove this Bot + // link with its busy label and tooltip, and the inline remove question that ends on the roster. + "Auto-send my Bots' replies to {who}": '我的 Bot 发给 {who} 的回复自动发送', + "Your Bots' replies to {who} go out without asking you first. What you type is not affected.": '你的 Bot 发给 {who} 的回复不再先问你。你输入的内容不受影响。', + 'Remove this Bot': '移除这个 Bot', + 'Removing…': '正在移除…', + 'Remove this Bot from your list and from your groups. This does not unfriend the owner.': '把这个 Bot 从你的列表和群聊中移除。这不会解除与主人的好友关系。', + 'Remove {bot} from your list? {note}': '把 {bot} 从你的列表中移除吗?{note}', + '{who} stays a friend: still shared through {bots}.': '{who} 仍是好友:仍通过 {bots} 共享。', + 'Your own Bots stay shared. {who} can share it again.': '你自己的 Bot 仍然保持共享。{who} 可以再次分享它。', + "Don't ask each time.": '不要每次都问。', // #3032: the four approval-card controls that were still drawn as bare English. "Waiting for the owner's approval": '等待 owner 批准', 'Auto-send from now on': '以后自动发送', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index 4ce593b0e..4fc73164a 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -7,8 +7,6 @@ "plugins/social/client.js:Chat paused", "plugins/social/client.js:Choose which of your Bots join.", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", - "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: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{}: ", @@ -25,10 +23,6 @@ "plugins/social/client.js:Point the camera at a FlyBot room code.", "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:Remove this Bot from your list and from your groups. This does not unfriend the owner.", - "plugins/social/client.js:Remove this Bot#1", - "plugins/social/client.js:Remove this Bot#2", - "plugins/social/client.js:Removing…", "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.", @@ -53,10 +47,8 @@ "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:You already joined with that link using other Bots. Leave the group first to join with different ones.", - "plugins/social/client.js:Your own Bots stay shared. {} can share it again.", "plugins/social/client.js:the group", "plugins/social/client.js:the room", - "plugins/social/client.js:{} stays a friend: still shared through {}.", "plugins/timeline/client.js:Communication map: who sent requests to whom", "plugins/timeline/client.js:Copy report", "plugins/timeline/client.js:Copy this window as a Markdown report", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index 7d03d4805..ed43b08df 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -2,16 +2,13 @@ "version": 1, "entries": [ "plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.", - "plugins/social/client.js:Auto-send my Bots' replies to {}", "plugins/social/client.js:Auto-send {} → room", "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:Invite grants {} only.", "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", - "plugins/social/client.js:Remove {} from your list? {}", "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.", - "plugins/social/client.js:Your Bots' replies to {} go out without asking you first. What you type is not affected.", "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 98b06c206..7f9f2d4f9 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,147 @@ const ZH = { +@@ -41,22 +41,158 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -999,6 +999,17 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'That Bot was removed from that home.': '那个 Bot 已从对方那里移除。', + 'Messages waiting for your approval': '等你批准的消息', + 'Waiting for approval': '等待批准', ++ // #3114 cut 23: a friend's Bot settings card — its Auto-send box and hint, the Remove this Bot ++ // link with its busy label and tooltip, and the inline remove question that ends on the roster. ++ "Auto-send my Bots' replies to {who}": '我的 Bot 发给 {who} 的回复自动发送', ++ "Your Bots' replies to {who} go out without asking you first. What you type is not affected.": '你的 Bot 发给 {who} 的回复不再先问你。你输入的内容不受影响。', ++ 'Remove this Bot': '移除这个 Bot', ++ 'Removing…': '正在移除…', ++ 'Remove this Bot from your list and from your groups. This does not unfriend the owner.': '把这个 Bot 从你的列表和群聊中移除。这不会解除与主人的好友关系。', ++ 'Remove {bot} from your list? {note}': '把 {bot} 从你的列表中移除吗?{note}', ++ '{who} stays a friend: still shared through {bots}.': '{who} 仍是好友:仍通过 {bots} 共享。', ++ 'Your own Bots stay shared. {who} can share it again.': '你自己的 Bot 仍然保持共享。{who} 可以再次分享它。', ++ "Don't ask each time.": '不要每次都问。', + // #3032: the four approval-card controls that were still drawn as bare English. + "Waiting for the owner's approval": '等待 owner 批准', + 'Auto-send from now on': '以后自动发送', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index f5d82a148..42284b14e 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,146 @@ var ZH = { +@@ -78,21 +78,157 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -263,6 +263,17 @@ diff --git a/client.js b/client.js + "That Bot was removed from that home.": "那个 Bot 已从对方那里移除。", + "Messages waiting for your approval": "等你批准的消息", + "Waiting for approval": "等待批准", ++ // #3114 cut 23: a friend's Bot settings card — its Auto-send box and hint, the Remove this Bot ++ // link with its busy label and tooltip, and the inline remove question that ends on the roster. ++ "Auto-send my Bots' replies to {who}": "我的 Bot 发给 {who} 的回复自动发送", ++ "Your Bots' replies to {who} go out without asking you first. What you type is not affected.": "你的 Bot 发给 {who} 的回复不再先问你。你输入的内容不受影响。", ++ "Remove this Bot": "移除这个 Bot", ++ "Removing…": "正在移除…", ++ "Remove this Bot from your list and from your groups. This does not unfriend the owner.": "把这个 Bot 从你的列表和群聊中移除。这不会解除与主人的好友关系。", ++ "Remove {bot} from your list? {note}": "把 {bot} 从你的列表中移除吗?{note}", ++ "{who} stays a friend: still shared through {bots}.": "{who} 仍是好友:仍通过 {bots} 共享。", ++ "Your own Bots stay shared. {who} can share it again.": "你自己的 Bot 仍然保持共享。{who} 可以再次分享它。", ++ "Don't ask each time.": "不要每次都问。", + // #3032: the four approval-card controls that were still drawn as bare English. + "Waiting for the owner's approval": "等待 owner 批准", + "Auto-send from now on": "以后自动发送", 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 4ce593b0e..4fc73164a 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -7,8 +7,6 @@ "plugins/social/client.js:Chat paused", "plugins/social/client.js:Choose which of your Bots join.", "plugins/social/client.js:Could not reach FlyBot. Check that it is still running.", - "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: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{}: ", @@ -25,10 +23,6 @@ "plugins/social/client.js:Point the camera at a FlyBot room code.", "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:Remove this Bot from your list and from your groups. This does not unfriend the owner.", - "plugins/social/client.js:Remove this Bot#1", - "plugins/social/client.js:Remove this Bot#2", - "plugins/social/client.js:Removing…", "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.", @@ -53,10 +47,8 @@ "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:You already joined with that link using other Bots. Leave the group first to join with different ones.", - "plugins/social/client.js:Your own Bots stay shared. {} can share it again.", "plugins/social/client.js:the group", "plugins/social/client.js:the room", - "plugins/social/client.js:{} stays a friend: still shared through {}.", "plugins/timeline/client.js:Communication map: who sent requests to whom", "plugins/timeline/client.js:Copy report", "plugins/timeline/client.js:Copy this window as a Markdown report", 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 7d03d4805..ed43b08df 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -2,16 +2,13 @@ "version": 1, "entries": [ "plugins/social/client.js:Asked to join {}. It opens in your sidebar as soon as their FlyBot seats your Bots.", - "plugins/social/client.js:Auto-send my Bots' replies to {}", "plugins/social/client.js:Auto-send {} → room", "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:Invite grants {} only.", "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", - "plugins/social/client.js:Remove {} from your list? {}", "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.", - "plugins/social/client.js:Your Bots' replies to {} go out without asking you first. What you type is not affected.", "plugins/social/client.js:{} Send your message again: it starts a new chat.", "plugins/timeline/client.js:Could not copy the report: {}", "plugins/timeline/client.js:Last {}", diff --git a/plugins/social/client.js b/plugins/social/client.js index 2a453ea08..694f809dd 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -553,7 +553,7 @@ window.__ModuleLoader__.load({ const AUTO_SEND_NOTE = "Don't ask each time." function FaceAutoSend({ on, busy, onChange, bot } = {}) { - return h('label', { className: 'fs-auto fs-face-auto', title: AUTO_SEND_NOTE, 'data-flybot': 'face-auto-bot' }, + return h('label', { className: 'fs-auto fs-face-auto', title: tr(AUTO_SEND_NOTE), 'data-flybot': 'face-auto-bot' }, h('input', { type: 'checkbox', checked: on === true, @@ -2890,7 +2890,7 @@ window.__ModuleLoader__.load({ function FriendBotRow({ bot, chat, renderBot, busy, onRemove }) { const [menu, setMenu] = useState(false) - const label = busy ? 'Removing…' : 'Remove this Bot' + const label = busy ? tr('Removing…') : tr('Remove this Bot') return h('div', { className: 'fs-row-wrap', 'data-flybot': 'friend-bot', @@ -2913,7 +2913,7 @@ window.__ModuleLoader__.load({ onClick: (event) => { event?.stopPropagation?.(); onRemove?.(bot) }, }, busy ? '…' : '×'), menu ? h('div', { className: 'fs-menu', role: 'menu', 'data-flybot': 'friend-bot-menu' }, - h('button', { type: 'button', role: 'menuitem', onClick: () => { setMenu(false); onRemove?.(bot) } }, 'Remove this Bot')) : null) + h('button', { type: 'button', role: 'menuitem', onClick: () => { setMenu(false); onRemove?.(bot) } }, tr('Remove this Bot'))) : null) } // Every home counts down to Bot Social's one deadline (#458): `offsetMs` is how far the server's @@ -3757,7 +3757,7 @@ window.__ModuleLoader__.load({ } finally { setSaving(false) } } const named = remote.homeName || remote.owner || '' - const who = named || home || 'Your friend' + const who = named || home || tr('Your friend') // #1001: a friend stays in the list while any of their Bots is still shared with any of mine, so // removing this one leaves the friend behind with no reason given. Name the link that keeps them: // the other Bots of the same friend the roster still lists. With none, there is nothing to name and @@ -3767,8 +3767,8 @@ window.__ModuleLoader__.load({ .map(other => String(other.name ?? '').trim()) .filter(name => name !== '') const keepLine = stillLinked.length > 0 - ? `${who} stays a friend: still shared through ${stillLinked.join(', ')}.` - : `Your own Bots stay shared. ${who} can share it again.` + ? tr('{who} stays a friend: still shared through {bots}.', { who, bots: stillLinked.join(', ') }) + : tr('Your own Bots stay shared. {who} can share it again.', { who }) // Asked inline, like Leave on a face room (#230), not with the browser's confirm box. const removeBot = async () => { setAsking(false) @@ -3786,25 +3786,25 @@ window.__ModuleLoader__.load({ // Auto-send for all my Bots to this person (#417 says what it covers; one Bot's own is in its Sharing). // The box holds the setting only; the destructive link sits apart, below it (#274). h('div', { className: 'fs-card fs-friend-auto', 'data-flybot': 'friend-auto-box' }, - h('label', { className: 'fs-auto', title: AUTO_SEND_NOTE, 'data-flybot': 'friend-auto-send' }, + h('label', { className: 'fs-auto', title: tr(AUTO_SEND_NOTE), 'data-flybot': 'friend-auto-send' }, h('input', { type: 'checkbox', checked: auto === true, disabled: saving || !home, onChange: e => toggleAuto(e.target.checked) }), - `Auto-send my Bots' replies to ${who}`), - h('div', { className: 'fs-hint', 'data-flybot': 'friend-auto-hint' }, `Your Bots' replies to ${who} go out without asking you first. What you type is not affected.`)), + tr("Auto-send my Bots' replies to {who}", { who })), + h('div', { className: 'fs-hint', 'data-flybot': 'friend-auto-hint' }, tr("Your Bots' replies to {who} go out without asking you first. What you type is not affected.", { who }))), h('div', { className: 'fs-friend-remove', 'data-flybot': 'friend-remove-row' }, asking ? h('span', { className: 'fs-leave-ask', 'data-flybot': 'remove-friend-bot-confirm' }, - h('span', { className: 'fs-hint' }, `Remove ${botWithOwner(bot.name, named)} from your list? ${keepLine}`), + h('span', { className: 'fs-hint' }, tr('Remove {bot} from your list? {note}', { bot: botWithOwner(bot.name, named), note: keepLine })), h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'remove-friend-bot-yes', onClick: () => { void removeBot() } }, tr('Remove')), h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'remove-friend-bot-no', onClick: () => setAsking(false) }, tr('Keep'))) : h('button', { type: 'button', className: 'fs-link', 'data-flybot': 'remove-friend-bot', - title: 'Remove this Bot from your list and from your groups. This does not unfriend the owner.', - 'aria-label': busy ? 'Removing…' : 'Remove this Bot', + title: tr('Remove this Bot from your list and from your groups. This does not unfriend the owner.'), + 'aria-label': busy ? tr('Removing…') : tr('Remove this Bot'), 'aria-busy': busy || undefined, disabled: !!busy, onClick: () => setAsking(true), - }, busy ? 'Removing…' : 'Remove this Bot')), + }, busy ? tr('Removing…') : tr('Remove this Bot'))), error ? h('div', { className: 'fs-status', 'data-tone': 'error', role: 'status' }, error) : null) } diff --git a/plugins/social/test/add-friend-i18n.test.js b/plugins/social/test/add-friend-i18n.test.js index 15c4ff9d9..37fa1677d 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], [14, 21, 94]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [14, 18, 86]) // 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 new file mode 100644 index 000000000..34af295d7 --- /dev/null +++ b/plugins/social/test/friend-settings-i18n.test.js @@ -0,0 +1,155 @@ +// #3114 cut 23: a friend Bot's settings card (`FriendChatSettings`) drew its Auto-send box, its +// hint, the Remove this Bot link with its title and busy label, and the inline remove question as +// bare English in a zh window. This pins them: a zh window reads the dictionary's words, a window +// whose host has no translator keeps today's English word for word, and the two i18n baselines +// lose the pins those draws held. The same sentence also draws on the sidebar's friend row, whose +// menu item and aria-label has to travel with the dictionary key (#2998). +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 remove question is the fourth). +function loadApp(flybot, states = []) { + 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) + let seed = 0 + const createElement = (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat() }) + return registered[0].factory(() => ({ + createElement, Fragment: 'F', useEffect() {}, + useState: value => [seed < states.length ? states[seed++] : value, () => {}], + useRef: value => ({ current: value }), + })) +} + +// These cards are plain render functions once the effects are inert, so the tree is the render. +// Text is every string the tree paints, in draw order, so a card that keeps drawing English shows +// it in the list the assertion prints. +function draw(node, all = []) { + if (!node || typeof node !== 'object') return all + if (typeof node.type === 'function') return draw(node.type(node.props), all) + for (const child of node.children ?? []) { + if (typeof child === 'string') { if (child.trim()) all.push(child) } else draw(child, all) + } + return all +} +const button = (node, id) => { + if (typeof node?.type === 'function') return button(node.type(node.props), id) + return node?.props?.['data-flybot'] === id ? node : (node?.children ?? []).map(child => button(child, id)).find(Boolean) +} + +// A friend's Bot as the card reads it: the home names the person, the Bot carries its own name. +const friend = { id: 'b1', name: 'Eve', remote: { home: '@eve.home', handle: '@eve.bot', homeName: 'Eve' } } +const row = (window, states = [true], onRemove = () => {}) => loadApp(window, states).FriendBotRow({ + bot: { handle: '@eve.bot', name: 'Eve' }, + chat: { id: 'c1' }, + renderBot: () => ({ type: 'div', props: {}, children: ['Eve'] }), + onRemove, +}) + +test('#3114 cut 23: a friend Bot’s settings card speaks the window’s language', () => { + const card = loadApp(zhWindow).FriendChatSettings({ bot: friend }) + const drawn = draw(card) + // Every position this card draws is a dictionary entry, so a missing one names itself here. + for (const key of [ + "Auto-send my Bots' replies to {who}", + "Your Bots' replies to {who} go out without asking you first. What you type is not affected.", + 'Remove this Bot', 'Removing…', "Don't ask each time.", + ]) assert.ok(zh[key], `expected ${zh[key]} (${key}), saw ${JSON.stringify(drawn)}`) + assert.deepEqual(drawn, ['我的 Bot 发给 Eve 的回复自动发送', '你的 Bot 发给 Eve 的回复不再先问你。你输入的内容不受影响。', '移除这个 Bot']) + assert.equal(button(card, 'friend-auto-send').props.title, '不要每次都问。') + const remove = button(card, 'remove-friend-bot') + assert.equal(remove.props.title, '把这个 Bot 从你的列表和群聊中移除。这不会解除与主人的好友关系。') + assert.equal(remove.props['aria-label'], '移除这个 Bot') + + // The same sentence draws on the sidebar's friend row: its menu item and aria-label travel + // with the key, so a zh window never reads it bare next to a translated card (#2998). + const sidebar = row(zhWindow) + assert.deepEqual(draw(sidebar), ['Eve', '×', '移除这个 Bot']) + assert.equal(button(sidebar, 'remove-friend-bot').props['aria-label'], '移除这个 Bot') +}) + +test('#3114 cut 23: the inline remove question speaks the window’s language', () => { + // Asking is the fourth useState; the roster still lists the friend's other shared Bot, which is + // the sentence that keeps the friend in the list. + const linked = loadApp(zhWindow, [false, false, false, true, '']).FriendChatSettings({ + bot: friend, + roster: { remoteBots: [{ handle: '@eve.two', name: 'Eve Two', home: '@eve.home' }] }, + }) + assert.deepEqual(draw(linked), ['我的 Bot 发给 Eve 的回复自动发送', '你的 Bot 发给 Eve 的回复不再先问你。你输入的内容不受影响。', '把 Eve 从你的列表中移除吗?Eve 仍是好友:仍通过 Eve Two 共享。', '删除', '保留']) + assert.equal(button(linked, 'remove-friend-bot-yes').props['data-flybot'], 'remove-friend-bot-yes') + + // With no other Bot of that friend still shared, the question ends the other way. + const lone = loadApp(zhWindow, [false, false, false, true, '']).FriendChatSettings({ bot: friend, roster: { remoteBots: [] } }) + assert.deepEqual(draw(lone), ['我的 Bot 发给 Eve 的回复自动发送', '你的 Bot 发给 Eve 的回复不再先问你。你输入的内容不受影响。', '把 Eve 从你的列表中移除吗?你自己的 Bot 仍然保持共享。Eve 可以再次分享它。', '删除', '保留']) +}) + +test('#3114 cut 23: a host with no translator keeps today’s English', () => { + // `tr()` replaces a string only when the host answers for it, so today's English is the fallback + // character for character — the guard that this cut changes what a zh window reads, not the copy. + const card = loadApp(bareWindow).FriendChatSettings({ bot: friend }) + assert.deepEqual(draw(card), [ + "Auto-send my Bots' replies to Eve", + "Your Bots' replies to Eve go out without asking you first. What you type is not affected.", + 'Remove this Bot', + ]) + assert.equal(button(card, 'friend-auto-send').props.title, "Don't ask each time.") + assert.equal(button(card, 'remove-friend-bot').props.title, 'Remove this Bot from your list and from your groups. This does not unfriend the owner.') + assert.equal(button(card, 'remove-friend-bot').props['aria-label'], 'Remove this Bot') + const asking = loadApp(bareWindow, [false, false, false, true, '']).FriendChatSettings({ bot: friend, roster: { remoteBots: [] } }) + assert.deepEqual(draw(asking), ["Auto-send my Bots' replies to Eve", "Your Bots' replies to Eve go out without asking you first. What you type is not affected.", 'Remove Eve from your list? Your own Bots stay shared. Eve can share it again.', 'Remove', 'Keep']) + const sidebar = row(bareWindow) + assert.deepEqual(draw(sidebar), ['Eve', '×', 'Remove this Bot']) + assert.equal(button(sidebar, 'remove-friend-bot').props['aria-label'], 'Remove this Bot') +}) + +// 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', [ + "Don't ask each time.#1", "Don't ask each time.#2", + 'Remove this Bot#1', 'Remove this Bot#2', 'Removing…', + 'Remove this Bot from your list and from your groups. This does not unfriend the owner.', + '{} stays a friend: still shared through {}.', + 'Your own Bots stay shared. {} can share it again.', + ]], + ['i18n-template-draws.baseline.json', [ + "Auto-send my Bots' replies to {}", + "Your Bots' replies to {} go out without asking you first. What you type is not affected.", + 'Remove {} from your list? {}', + ]], +] +const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries + +test('#3114 cut 23: the two baselines lose these draws and nothing else', () => { + 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, + ], [14, 18, 86]) + // 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 9b5c056a3..849fb3738 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], [14, 21, 94]) + assert.deepEqual([entriesOf('i18n-plugins.baseline.json').length, entriesOf('i18n-template-draws.baseline.json').length, entriesOf('i18n-missing-entries.baseline.json').length], [14, 18, 86]) // 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.