From 1cc8ee0794dbb096634d0f772c8a571021bec59e Mon Sep 17 00:00:00 2001 From: Danyang Chen Date: Thu, 19 Nov 2026 15:27:19 +0800 Subject: [PATCH] Read the Social share cards in the window's language (#3114) The share-request card and the invite-accepted card drew their sentence, the asked hint, both buttons, the two `your Bot` fallbacks and the Sharing title as bare English, so a Chinese window read English on those two cards while the rest of the Social panel followed the window. `plugins/social/client.js` already has `tr()`; these eleven lines now go through it and the seven entries land in `core/src/client/i18n.js`, so the three i18n baselines drop the eight entries that pinned the draws. A window without a translator keeps today's English word for word. Fixes #3209 Part of #3114 Docs-not-needed: the two cards keep their layout, state and server calls; this cut adds seven zh dictionary entries and routes eleven existing literals through the panel's own tr(). docs/subsystems/social.md and core-client.md describe the panel and the bundle, not its copy. --- .../3114-social-share-cards-zh.changed.md | 1 + core/client.js | 9 + core/src/client/i18n.js | 12 ++ core/test/i18n-missing-entries.baseline.json | 3 - core/test/i18n-plugins.baseline.json | 2 - core/test/i18n-template-draws.baseline.json | 3 - patches/ds-bot/0001-core-fixes.patch | 14 +- patches/ds-bot/0008-client-bundle.patch | 11 +- .../test/i18n-missing-entries.baseline.json | 3 - .../files/test/i18n-plugins.baseline.json | 2 - .../test/i18n-template-draws.baseline.json | 3 - plugins/social/client.js | 22 +-- plugins/social/test/share-cards-i18n.test.js | 177 ++++++++++++++++++ 13 files changed, 233 insertions(+), 29 deletions(-) create mode 100644 changelog.d/3114-social-share-cards-zh.changed.md create mode 100644 plugins/social/test/share-cards-i18n.test.js diff --git a/changelog.d/3114-social-share-cards-zh.changed.md b/changelog.d/3114-social-share-cards-zh.changed.md new file mode 100644 index 000000000..ba5caf174 --- /dev/null +++ b/changelog.d/3114-social-share-cards-zh.changed.md @@ -0,0 +1 @@ +The Social panel's share-request and invite-accepted cards — their sentence, hint line, buttons, and the **Open …'s Sharing** title — now follow the window's language, so a Chinese window no longer draws English there; a window without a translator still reads today's English ([#3114](https://github.com/ThinkFlowLab/FlyBot/issues/3114)). diff --git a/core/client.js b/core/client.js index ff49f69e9..c395cd066 100644 --- a/core/client.js +++ b/core/client.js @@ -458,6 +458,15 @@ var ZH = { "Open settings to set up a custom model": "打开设置配置自定义模型", "FlyBot": "FlyBot", "FlyBot core": "FlyBot 核心", + // Social's two notice cards (#3114): the share request and the accepted invite read in the + // window's language. `Dismiss` and `your Bot` already carry their Chinese above. + "A friend": "一位好友", + "{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.": "{name} 接受了你的邀请,可以给 {bot} 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。", + "You asked them to share a Bot.": "你已经请对方分享一个 Bot。", + "Ask them to share a Bot": "请对方分享一个 Bot", + "{name} tried to start a chat with {bot}. {bot} is not shared with them.": "{name} 想和 {bot} 开始聊天,但 {bot} 没有分享给对方。", + "Open {bot}'s Sharing": "打开 {bot} 的分享", + "Share {bot}…": "分享 {bot}…", // Header "Message {name}": "给 {name} 发消息", Message: "发消息", diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index 2cd30355d..d1e07a07f 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -426,6 +426,18 @@ const ZH = { 'FlyBot': 'FlyBot', 'FlyBot core': 'FlyBot 核心', + // Social's two notice cards (#3114): the share request and the accepted invite read in the + // window's language. `Dismiss` and `your Bot` already carry their Chinese above. + 'A friend': '一位好友', + '{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.': + '{name} 接受了你的邀请,可以给 {bot} 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。', + 'You asked them to share a Bot.': '你已经请对方分享一个 Bot。', + 'Ask them to share a Bot': '请对方分享一个 Bot', + '{name} tried to start a chat with {bot}. {bot} is not shared with them.': + '{name} 想和 {bot} 开始聊天,但 {bot} 没有分享给对方。', + "Open {bot}'s Sharing": '打开 {bot} 的分享', + 'Share {bot}…': '分享 {bot}…', + // Header 'Message {name}': '给 {name} 发消息', Message: '发消息', diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index b04c0351c..ffbd2fa3d 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -5,7 +5,6 @@ "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:Ask them to share a Bot", "plugins/social/client.js:Auto-send", "plugins/social/client.js:Auto-send off", "plugins/social/client.js:Auto-send on", @@ -101,7 +100,6 @@ "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:You asked them to share a Bot.", "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", @@ -109,7 +107,6 @@ "plugins/social/client.js:the group", "plugins/social/client.js:the room", "plugins/social/client.js:{} (you)", - "plugins/social/client.js:{} accepted your invite. They can message {}. You cannot message them until they share a Bot with 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-plugins.baseline.json b/core/test/i18n-plugins.baseline.json index 0fe2ab5b2..9e9ad3624 100644 --- a/core/test/i18n-plugins.baseline.json +++ b/core/test/i18n-plugins.baseline.json @@ -6,8 +6,6 @@ "plugins/social/client.js:Copied#2", "plugins/social/client.js:Copy", "plugins/social/client.js:Copy link", - "plugins/social/client.js:Dismiss#1", - "plugins/social/client.js:Dismiss#2", "plugins/social/client.js:New link", "plugins/social/client.js:Your Bot Social handle", "plugins/social/client.js:Your Bots", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index 40af9437f..a686acef1 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -11,7 +11,6 @@ "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", "plugins/social/client.js:Invite link for {}", "plugins/social/client.js:One click shares {} with someone you already know. No invite link. They can decline; you can Revoke in People with access.", - "plugins/social/client.js:Open {}'s Sharing", "plugins/social/client.js:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", "plugins/social/client.js:Revoke {}#1", @@ -20,13 +19,11 @@ "plugins/social/client.js:Scanned {}.", "plugins/social/client.js:Scanned {}. Pick a Bot to join.", "plugins/social/client.js:Share {} with {}", - "plugins/social/client.js:Share {}…", "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:You are {}", "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/social/client.js:{} failed: {}", - "plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#1", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#2", "plugins/timeline/client.js:Could not copy the report: {}", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index aea12da81..4f3f46aa7 100644 --- a/patches/ds-bot/0001-core-fixes.patch +++ b/patches/ds-bot/0001-core-fixes.patch @@ -1055,7 +1055,7 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js Connected: '已连接', Disconnect: '断开', Connect: '连接', -@@ -105,17 +105,64 @@ const ZH = { +@@ -105,17 +105,76 @@ const ZH = { 'GitHub addresses must start with https://': 'GitHub 地址必须以 https:// 开头', 'This DSH cannot load connectors': '这个 DSH 不能加载连接器', 'No such connector': '没有这个连接器', @@ -1121,6 +1121,18 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js - 'DS Bot': 'DS Bot', + 'FlyBot': 'FlyBot', + 'FlyBot core': 'FlyBot 核心', ++ ++ // Social's two notice cards (#3114): the share request and the accepted invite read in the ++ // window's language. `Dismiss` and `your Bot` already carry their Chinese above. ++ 'A friend': '一位好友', ++ '{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.': ++ '{name} 接受了你的邀请,可以给 {bot} 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。', ++ 'You asked them to share a Bot.': '你已经请对方分享一个 Bot。', ++ 'Ask them to share a Bot': '请对方分享一个 Bot', ++ '{name} tried to start a chat with {bot}. {bot} is not shared with them.': ++ '{name} 想和 {bot} 开始聊天,但 {bot} 没有分享给对方。', ++ "Open {bot}'s Sharing": '打开 {bot} 的分享', ++ 'Share {bot}…': '分享 {bot}…', // Header 'Message {name}': '给 {name} 发消息', diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 3185120a9..6aeb839a3 100644 --- a/patches/ds-bot/0008-client-bundle.patch +++ b/patches/ds-bot/0008-client-bundle.patch @@ -319,7 +319,7 @@ diff --git a/client.js b/client.js Connected: "已连接", Disconnect: "断开", Connect: "连接", -@@ -141,17 +141,64 @@ var ZH = { +@@ -141,17 +141,73 @@ var ZH = { "GitHub addresses must start with https://": "GitHub 地址必须以 https:// 开头", "This DSH cannot load connectors": "这个 DSH 不能加载连接器", "No such connector": "没有这个连接器", @@ -385,6 +385,15 @@ diff --git a/client.js b/client.js - "DS Bot": "DS Bot", + "FlyBot": "FlyBot", + "FlyBot core": "FlyBot 核心", ++ // Social's two notice cards (#3114): the share request and the accepted invite read in the ++ // window's language. `Dismiss` and `your Bot` already carry their Chinese above. ++ "A friend": "一位好友", ++ "{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.": "{name} 接受了你的邀请,可以给 {bot} 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。", ++ "You asked them to share a Bot.": "你已经请对方分享一个 Bot。", ++ "Ask them to share a Bot": "请对方分享一个 Bot", ++ "{name} tried to start a chat with {bot}. {bot} is not shared with them.": "{name} 想和 {bot} 开始聊天,但 {bot} 没有分享给对方。", ++ "Open {bot}'s Sharing": "打开 {bot} 的分享", ++ "Share {bot}…": "分享 {bot}…", // Header "Message {name}": "给 {name} 发消息", Message: "发消息", 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 b04c0351c..ffbd2fa3d 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -5,7 +5,6 @@ "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:Ask them to share a Bot", "plugins/social/client.js:Auto-send", "plugins/social/client.js:Auto-send off", "plugins/social/client.js:Auto-send on", @@ -101,7 +100,6 @@ "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:You asked them to share a Bot.", "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", @@ -109,7 +107,6 @@ "plugins/social/client.js:the group", "plugins/social/client.js:the room", "plugins/social/client.js:{} (you)", - "plugins/social/client.js:{} accepted your invite. They can message {}. You cannot message them until they share a Bot with 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-plugins.baseline.json b/patches/ds-bot/files/test/i18n-plugins.baseline.json index 0fe2ab5b2..9e9ad3624 100644 --- a/patches/ds-bot/files/test/i18n-plugins.baseline.json +++ b/patches/ds-bot/files/test/i18n-plugins.baseline.json @@ -6,8 +6,6 @@ "plugins/social/client.js:Copied#2", "plugins/social/client.js:Copy", "plugins/social/client.js:Copy link", - "plugins/social/client.js:Dismiss#1", - "plugins/social/client.js:Dismiss#2", "plugins/social/client.js:New link", "plugins/social/client.js:Your Bot Social handle", "plugins/social/client.js:Your Bots", 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 40af9437f..a686acef1 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -11,7 +11,6 @@ "plugins/social/client.js:Invite grants {} only. Revoke anytime in People with access.", "plugins/social/client.js:Invite link for {}", "plugins/social/client.js:One click shares {} with someone you already know. No invite link. They can decline; you can Revoke in People with access.", - "plugins/social/client.js:Open {}'s Sharing", "plugins/social/client.js:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", "plugins/social/client.js:Revoke {}#1", @@ -20,13 +19,11 @@ "plugins/social/client.js:Scanned {}.", "plugins/social/client.js:Scanned {}. Pick a Bot to join.", "plugins/social/client.js:Share {} with {}", - "plugins/social/client.js:Share {}…", "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:You are {}", "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/social/client.js:{} failed: {}", - "plugins/social/client.js:{} tried to start a chat with {}. {} is not shared with them.", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#1", "plugins/social/client.js:{}'s replies to {} go out without asking you first.#2", "plugins/timeline/client.js:Could not copy the report: {}", diff --git a/plugins/social/client.js b/plugins/social/client.js index d089f00d1..6c58c51ec 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -3312,26 +3312,26 @@ window.__ModuleLoader__.load({ // Someone accepted an invite to one of my Bots (#1054). One-way stays; this card is the inviter's // feedback and the one step that asks them to share a Bot back. Asking does not grant anything. function acceptNoticeSentence(item) { - const who = item?.owner ? `${item.name} (${item.owner})` : (item?.name || 'A friend') - const bot = item?.botName || 'your Bot' - return `${who} accepted your invite. They can message ${bot}. You cannot message them until they share a Bot with you.` + const who = item?.owner ? `${item.name} (${item.owner})` : (item?.name || tr('A friend')) + const bot = item?.botName || tr('your Bot') + return tr('{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.', { name: who, bot }) } function AcceptNotices({ items, onAsk, onDismiss, locked = false } = {}) { if (!Array.isArray(items) || items.length === 0) return null return h('div', { className: 'fs-share-requests', 'data-flybot': 'accept-notices' }, items.map((item) => h('div', { key: item.id, className: 'fs-card fs-share-request', role: 'status', 'data-flybot': 'accept-notice' }, h('div', { className: 'fs-hint', 'data-flybot': 'accept-notice-text' }, acceptNoticeSentence(item)), - item.asked ? h('div', { className: 'fs-hint', 'data-flybot': 'accept-notice-asked' }, 'You asked them to share a Bot.') : null, + item.asked ? h('div', { className: 'fs-hint', 'data-flybot': 'accept-notice-asked' }, tr('You asked them to share a Bot.')) : null, // #2219: asking and dismissing are writes; a read-only window still reads the notice. locked ? null : h('div', { className: 'fs-line' }, - h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'accept-notice-dismiss', onClick: () => onDismiss?.(item) }, 'Dismiss'), + h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'accept-notice-dismiss', onClick: () => onDismiss?.(item) }, tr('Dismiss')), h('button', { type: 'button', className: 'fs-btn fs-btn-sm fs-btn-primary', 'data-flybot': 'accept-notice-ask', disabled: item.asked === true, onClick: () => { if (!item.asked) onAsk?.(item) }, - }, 'Ask them to share a Bot'))))) + }, tr('Ask them to share a Bot')))))) } // "Share this Bot?" (#336): a friend's Bot tried to start a chat with one of my Bots that is not @@ -3342,20 +3342,20 @@ window.__ModuleLoader__.load({ return h('div', { className: 'fs-share-requests', 'data-flybot': 'share-requests' }, items.map((item) => { const who = item.owner ? `${item.name} (${item.owner})` : item.name - const bot = item.botName || 'your Bot' + const bot = item.botName || tr('your Bot') return h('div', { key: item.id, className: 'fs-card fs-share-request', role: 'status', 'data-flybot': 'share-request' }, - h('div', { className: 'fs-hint', 'data-flybot': 'share-request-text' }, `${who} tried to start a chat with ${bot}. ${bot} is not shared with them.`), + h('div', { className: 'fs-hint', 'data-flybot': 'share-request-text' }, tr('{name} tried to start a chat with {bot}. {bot} is not shared with them.', { name: who, bot })), h('div', { className: 'fs-line' }, // #2219: dismissing is a write; opening the Sharing page is navigation and stays. - locked ? null : h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'share-request-dismiss', onClick: () => onDismiss?.(item) }, 'Dismiss'), + locked ? null : h('button', { type: 'button', className: 'fs-btn fs-btn-sm', 'data-flybot': 'share-request-dismiss', onClick: () => onDismiss?.(item) }, tr('Dismiss')), h('button', { type: 'button', className: 'fs-btn fs-btn-sm fs-btn-primary', 'data-flybot': 'share-request-open', - title: `Open ${bot}'s Sharing`, + title: tr("Open {bot}'s Sharing", { bot }), disabled: typeof actions?.openSettings !== 'function', onClick: () => actions.openSettings('bots', item.botId), - }, `Share ${bot}…`))) + }, tr('Share {bot}…', { bot })))) })) } diff --git a/plugins/social/test/share-cards-i18n.test.js b/plugins/social/test/share-cards-i18n.test.js new file mode 100644 index 000000000..e157e2b0a --- /dev/null +++ b/plugins/social/test/share-cards-i18n.test.js @@ -0,0 +1,177 @@ +// #3114 cut 18: the Social panel's share-request card and invite-accepted card drew their +// sentence, the "you already asked" hint, both buttons and the Open …'s Sharing title as bare +// English, while the rest of the panel followed the window's language — a Chinese window read +// English on those two cards only. `plugins/social/client.js` already carries `tr()` for the rest +// of the panel, so this pins all of it: a zh window reads the dictionary's words, a window whose +// host has no translator at all keeps today's English word for word, and the three i18n baselines +// lose the eight entries that pinned these draws. +// +// The copy is read out of the rendered tree, not out of the source: a string that reaches the +// card through the dictionary and a string that is merely spelled like the dictionary's +// translation look the same in a diff and differ here. +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 +} + +// A host with a translator, and a host without one: `tr()` then falls back to the English it was +// handed, so the two windows differ only in the copy the panel draws. +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. +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 createElement = (type, props, ...children) => ({ type, props: props ?? {}, children: children.flat() }) + return registered[0].factory(() => ({ + createElement, Fragment: 'F', useEffect() {}, useState: value => [value, () => {}], useRef: value => ({ current: value }), useMemo: fn => fn(), + })) +} + +// A friend's Bot with its owner reads `Helper (Eve)`; the accepted invite names our Bot `Chief`. +const shareItem = { id: 'evt1', botId: 'b1', botName: 'Writer', from: '@helper.eve.home', name: 'Helper', owner: 'Eve' } +const notice = { id: 'n1', name: 'Chief Grant', owner: 'SelfB1025', botName: 'Chief', asked: true } + +// These two cards are plain render functions — no hooks, no effects — so the tree is the render. +function walk(node, all = []) { + if (!node || typeof node !== 'object') return all + if (typeof node.type === 'function') return walk(node.type(node.props), all) + all.push(node) + for (const child of node.children ?? []) walk(child, all) + return all +} + +const shareCard = (app, props = {}) => walk(app.ShareRequests({ items: [shareItem], actions: {}, ...props })) +const acceptCard = (app, props = {}) => walk(app.AcceptNotices({ items: [notice], ...props })) +const textOf = (nodes, id) => (nodes.find(node => node.props?.['data-flybot'] === id)?.children ?? []).join('') +const buttonsOf = nodes => nodes.filter(node => node.type === 'button') +const buttonLabels = nodes => buttonsOf(nodes).map(node => node.children.join('')) + +test('#3110: a zh window reads the share request card in Chinese', () => { + const nodes = shareCard(loadApp(zhWindow)) + const text = textOf(nodes, 'share-request-text') + assert.equal(text, 'Helper (Eve) 想和 Writer 开始聊天,但 Writer 没有分享给对方。', `the share request still reads: ${text}`) + assert.doesNotMatch(text, /tried to start a chat with/, 'the English sentence is gone from a zh window') + assert.deepEqual(buttonLabels(nodes), ['关闭', '分享 Writer…'], 'both buttons follow the window too') + assert.equal(buttonsOf(nodes)[1].props.title, '打开 Writer 的分享', 'the Sharing title follows the window too') + + // Both fallback names are dictionary entries of their own: a request whose Bot has no name yet + // reads `your Bot`, which is Chinese in a zh window as well. + const nameless = walk(loadApp(zhWindow).ShareRequests({ items: [{ id: 'evt2', name: 'Helper', owner: 'Eve' }], actions: {} })) + assert.equal(textOf(nameless, 'share-request-text'), 'Helper (Eve) 想和 你的 Bot 开始聊天,但 你的 Bot 没有分享给对方。') + + // The owner is optional: without one the card names the friend's Bot alone. + const ownerless = walk(loadApp(zhWindow).ShareRequests({ items: [{ ...shareItem, owner: '' }], actions: {} })) + assert.equal(textOf(ownerless, 'share-request-text'), 'Helper 想和 Writer 开始聊天,但 Writer 没有分享给对方。') + + // #2219: a read-only window still reads the card; only the write button is missing. + const locked = shareCard(loadApp(zhWindow), { locked: true }) + assert.equal(textOf(locked, 'share-request-text'), 'Helper (Eve) 想和 Writer 开始聊天,但 Writer 没有分享给对方。') + assert.deepEqual(buttonLabels(locked), ['分享 Writer…'], 'the read-only window drops only Dismiss') +}) + +test('#3110: a zh window reads the accept notice card in Chinese', () => { + const nodes = acceptCard(loadApp(zhWindow)) + const text = textOf(nodes, 'accept-notice-text') + assert.equal(text, 'Chief Grant (SelfB1025) 接受了你的邀请,可以给 Chief 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。', `the accept notice still reads: ${text}`) + assert.doesNotMatch(text, /accepted your invite/, 'the English sentence is gone from a zh window') + assert.equal(textOf(nodes, 'accept-notice-asked'), '你已经请对方分享一个 Bot。', 'the hint line follows the window too') + assert.deepEqual(buttonLabels(nodes), ['关闭', '请对方分享一个 Bot'], 'both buttons follow the window too') + + // A notice that carries no Bot name and no owner reads both fallbacks through the translator. + // The owner is what makes the parenthesised form: without one the card names the Bot alone. + const ownerless = walk(loadApp(zhWindow).AcceptNotices({ items: [{ ...notice, owner: '' }] })) + assert.match(textOf(ownerless, 'accept-notice-text'), /^Chief Grant 接受了你的邀请/) + const nameless = walk(loadApp(zhWindow).AcceptNotices({ items: [{ id: 'n3' }] })) + const fallback = textOf(nameless, 'accept-notice-text') + assert.match(fallback, /^一位好友 接受了你的邀请/, 'the missing name reads `A friend` in Chinese') + assert.match(fallback, /可以给 你的 Bot 发消息/, 'the missing Bot name reads `your Bot` in Chinese') + + // A notice nobody has asked about yet draws no hint line, and a read-only one keeps its words. + const unasked = walk(loadApp(zhWindow).AcceptNotices({ items: [{ ...notice, asked: false }] })) + assert.equal(textOf(unasked, 'accept-notice-asked'), '', 'the hint line is only drawn once we asked') + const locked = acceptCard(loadApp(zhWindow), { locked: true }) + assert.equal(textOf(locked, 'accept-notice-asked'), '你已经请对方分享一个 Bot。') + assert.deepEqual(buttonLabels(locked), [], 'the read-only window drops both writes') +}) + +// 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 pinnedDraws = [ + ['i18n-template-draws.baseline.json', [ + "Open {}'s Sharing", + 'Share {}…', + '{} tried to start a chat with {}. {} is not shared with them.', + ]], + ['i18n-missing-entries.baseline.json', [ + 'Ask them to share a Bot', + 'You asked them to share a Bot.', + '{} accepted your invite. They can message {}. You cannot message them until they share a Bot with you.', + ]], +] +const baselineEntries = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries + +test("#3110: the i18n baselines no longer pin these draws, and a window without a translator keeps today's English", () => { + const left = [] + for (const [file, keys] of pinnedDraws) { + const entries = baselineEntries(file) + for (const key of keys) { + const id = `plugins/social/client.js:${key}` + if (entries.includes(id)) left.push(id) + } + } + assert.deepEqual(left, [], `the baselines still pin an English draw: ${left.join(', ')}`) + + // The third baseline is the bare-draw view of the same two `Dismiss` buttons. + assert.deepEqual(baselineEntries('i18n-plugins.baseline.json').filter(id => id.startsWith('plugins/social/client.js:Dismiss')), + [], 'both Dismiss draws are translated, so both entries leave as well') + + // 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. + const app = loadApp(bareWindow) + const share = shareCard(app) + assert.equal(textOf(share, 'share-request-text'), 'Helper (Eve) tried to start a chat with Writer. Writer is not shared with them.') + assert.deepEqual(buttonLabels(share), ['Dismiss', 'Share Writer…']) + assert.equal(buttonsOf(share)[1].props.title, "Open Writer's Sharing") + // The fallback names keep today's English too, so the same card reads as it did before this cut. + const nameless = walk(app.AcceptNotices({ items: [{ id: 'n4' }] })) + assert.match(textOf(nameless, 'accept-notice-text'), /^A friend accepted your invite\./) + assert.match(textOf(nameless, 'accept-notice-text'), /They can message your Bot\./) + + const accept = acceptCard(app) + assert.equal(textOf(accept, 'accept-notice-text'), 'Chief Grant (SelfB1025) accepted your invite. They can message Chief. You cannot message them until they share a Bot with you.') + assert.equal(textOf(accept, 'accept-notice-asked'), 'You asked them to share a Bot.') + assert.deepEqual(buttonLabels(accept), ['Dismiss', 'Ask them to share a Bot']) + + // The dictionary carries the seven entries this cut adds, verbatim, so a key renamed on one side + // and not the other is a red test rather than a card that keeps drawing English. + const added = { + 'A friend': '一位好友', + 'You asked them to share a Bot.': '你已经请对方分享一个 Bot。', + 'Ask them to share a Bot': '请对方分享一个 Bot', + "Open {bot}'s Sharing": '打开 {bot} 的分享', + 'Share {bot}…': '分享 {bot}…', + '{name} accepted your invite. They can message {bot}. You cannot message them until they share a Bot with you.': + '{name} 接受了你的邀请,可以给 {bot} 发消息。在对方分享一个 Bot 给你之前,你还不能给对方发消息。', + '{name} tried to start a chat with {bot}. {bot} is not shared with them.': + '{name} 想和 {bot} 开始聊天,但 {bot} 没有分享给对方。', + } + for (const [key, value] of Object.entries(added)) assert.equal(zh[key], value, `the dictionary carries ${key}`) + // The two names the panel already translated are reused, never added twice. + assert.deepEqual([zh.Dismiss, zh['your Bot']], ['关闭', '你的 Bot']) +})