diff --git a/changelog.d/3215-sharing-page-i18n.fixed.md b/changelog.d/3215-sharing-page-i18n.fixed.md new file mode 100644 index 000000000..e22ac4ff5 --- /dev/null +++ b/changelog.d/3215-sharing-page-i18n.fixed.md @@ -0,0 +1 @@ +A Bot's Sharing page now reads in the window's language: the People-with-access card and the share-with-a-friend card stop drawing bare English in a Chinese window ([#3215](https://github.com/ThinkFlowLab/FlyBot/issues/3215)). diff --git a/core/client.js b/core/client.js index 33bc98002..19ab392e1 100644 --- a/core/client.js +++ b/core/client.js @@ -267,6 +267,31 @@ var ZH = { "outside the tree": "不在树中", Undo: "撤销", "no longer shared": "已不再共享", + // #3114 cut 20: a Bot's Sharing page — the People-with-access card, its Auto-send switch and + // inline revoke question, and the share-with-a-friend card. + "One row per Bot. Default: nobody, Chief included.": "每行一个 Bot。默认谁都没有,包括 Chief。", + "One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.": "每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。", + "Nobody has this Bot yet. Copy an invite link above and send it to a friend.": "还没有人拿到这个 Bot。复制上面的邀请链接发给朋友。", + "Auto-send": "自动发送", + "Auto-send on": "自动发送已开", + "Auto-send off": "自动发送已关", + "Auto-send {name} → {who}": "{name} 发给 {who} 的消息自动发送", + "{name}’s replies to {who} go out without asking you first.": "{name} 发给 {who} 的回复不再先问你。", + Revoke: "撤销授权", + "Revoke {name}": "撤销 {name} 的授权", + "Revoking…": "正在撤销…", + "Revoke {who}? They lose this Bot.": "撤销 {who} 的授权?对方将失去这个 Bot。", + "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": "这个人", + "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…": "正在加载朋友…", + "No friends left to share with. Invite someone new above, or they already have this Bot.": "没有可分享的朋友了。在上面邀请新朋友,或者他们已经拿到了这个 Bot。", + Share: "分享", + "Share {name} with {who}": "把 {name} 分享给 {who}", + "Sharing…": "正在分享…", + "That Bot was removed from that home.": "那个 Bot 已从对方那里移除。", "Messages waiting for your approval": "等你批准的消息", "Waiting for approval": "等待批准", // #3032: the four approval-card controls that were still drawn as bare English. diff --git a/core/src/client/i18n.js b/core/src/client/i18n.js index cc52f45e4..16ae5e104 100644 --- a/core/src/client/i18n.js +++ b/core/src/client/i18n.js @@ -234,6 +234,31 @@ const ZH = { 'outside the tree': '不在树中', Undo: '撤销', 'no longer shared': '已不再共享', + // #3114 cut 20: a Bot's Sharing page — the People-with-access card, its Auto-send switch and + // inline revoke question, and the share-with-a-friend card. + 'One row per Bot. Default: nobody, Chief included.': '每行一个 Bot。默认谁都没有,包括 Chief。', + 'One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.': '每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。', + 'Nobody has this Bot yet. Copy an invite link above and send it to a friend.': '还没有人拿到这个 Bot。复制上面的邀请链接发给朋友。', + 'Auto-send': '自动发送', + 'Auto-send on': '自动发送已开', + 'Auto-send off': '自动发送已关', + 'Auto-send {name} → {who}': '{name} 发给 {who} 的消息自动发送', + '{name}’s replies to {who} go out without asking you first.': '{name} 发给 {who} 的回复不再先问你。', + Revoke: '撤销授权', + 'Revoke {name}': '撤销 {name} 的授权', + 'Revoking…': '正在撤销…', + 'Revoke {who}? They lose this Bot.': '撤销 {who} 的授权?对方将失去这个 Bot。', + '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': '这个人', + '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…': '正在加载朋友…', + 'No friends left to share with. Invite someone new above, or they already have this Bot.': '没有可分享的朋友了。在上面邀请新朋友,或者他们已经拿到了这个 Bot。', + Share: '分享', + 'Share {name} with {who}': '把 {name} 分享给 {who}', + 'Sharing…': '正在分享…', + 'That Bot was removed from that home.': '那个 Bot 已从对方那里移除。', 'Messages waiting for your approval': '等你批准的消息', 'Waiting for approval': '等待批准', // #3032: the four approval-card controls that were still drawn as bare English. diff --git a/core/test/i18n-missing-entries.baseline.json b/core/test/i18n-missing-entries.baseline.json index f1787dbe1..8921cc238 100644 --- a/core/test/i18n-missing-entries.baseline.json +++ b/core/test/i18n-missing-entries.baseline.json @@ -5,9 +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:Auto-send", - "plugins/social/client.js:Auto-send off", - "plugins/social/client.js:Auto-send on", "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.", @@ -37,13 +34,9 @@ "plugins/social/client.js:Leave#1", "plugins/social/client.js:Leave#2", "plugins/social/client.js:Link ready", - "plugins/social/client.js:Loading friends…", "plugins/social/client.js:Loading your Bots…", "plugins/social/client.js:Looking up that room…#1", "plugins/social/client.js:Looking up that room…#2", - "plugins/social/client.js:No friends left to share with. Invite someone new above, or they already have this Bot.", - "plugins/social/client.js:Nobody has this Bot yet. Copy an invite link above and send it to a friend.", - "plugins/social/client.js:One row per Bot. Default: nobody, Chief included.", "plugins/social/client.js:Past rooms", "plugins/social/client.js:Paste invite link or code", "plugins/social/client.js:Point the camera at a FlyBot room code.", @@ -54,27 +47,18 @@ "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:Revoke {}? They lose this Bot in {} room{}.", - "plugins/social/client.js:Revoke {}? They lose this Bot.", - "plugins/social/client.js:Revoke#1", - "plugins/social/client.js:Revoke#2", - "plugins/social/client.js:Revoking…", "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.", - "plugins/social/client.js:Share", "plugins/social/client.js:Share ", - "plugins/social/client.js:Share with a friend", - "plugins/social/client.js:Sharing…", "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 Bot was removed from that home.", "plugins/social/client.js:That is not a FlyBot room code. Ask for the 6-digit number instead.", "plugins/social/client.js:That is not an invite link. It looks like https://…/r/…", "plugins/social/client.js:That link cannot seat these Bots. Ask for a new one.", diff --git a/core/test/i18n-template-draws.baseline.json b/core/test/i18n-template-draws.baseline.json index 764dbee01..62e6b87d0 100644 --- a/core/test/i18n-template-draws.baseline.json +++ b/core/test/i18n-template-draws.baseline.json @@ -4,28 +4,21 @@ "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 {} → {}", "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:Copy invite link for {}", "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: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:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", - "plugins/social/client.js:Revoke {}#1", - "plugins/social/client.js:Revoke {}#2", "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:Share {} with {}", "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:{}'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: {}", "plugins/timeline/client.js:Last {}", "plugins/timeline/client.js:Looking back: window ends at {}.", diff --git a/patches/ds-bot/0001-core-fixes.patch b/patches/ds-bot/0001-core-fixes.patch index 54f7efc7a..6da945192 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,107 @@ const ZH = { +@@ -41,22 +41,132 @@ const ZH = { ' and ': '、', and: '和', '{count} members': '{count} 位成员', @@ -957,6 +957,31 @@ diff --git a/src/client/i18n.js b/src/client/i18n.js + 'outside the tree': '不在树中', + Undo: '撤销', + 'no longer shared': '已不再共享', ++ // #3114 cut 20: a Bot's Sharing page — the People-with-access card, its Auto-send switch and ++ // inline revoke question, and the share-with-a-friend card. ++ 'One row per Bot. Default: nobody, Chief included.': '每行一个 Bot。默认谁都没有,包括 Chief。', ++ 'One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.': '每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。', ++ 'Nobody has this Bot yet. Copy an invite link above and send it to a friend.': '还没有人拿到这个 Bot。复制上面的邀请链接发给朋友。', ++ 'Auto-send': '自动发送', ++ 'Auto-send on': '自动发送已开', ++ 'Auto-send off': '自动发送已关', ++ 'Auto-send {name} → {who}': '{name} 发给 {who} 的消息自动发送', ++ '{name}’s replies to {who} go out without asking you first.': '{name} 发给 {who} 的回复不再先问你。', ++ Revoke: '撤销授权', ++ 'Revoke {name}': '撤销 {name} 的授权', ++ 'Revoking…': '正在撤销…', ++ 'Revoke {who}? They lose this Bot.': '撤销 {who} 的授权?对方将失去这个 Bot。', ++ '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': '这个人', ++ '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…': '正在加载朋友…', ++ 'No friends left to share with. Invite someone new above, or they already have this Bot.': '没有可分享的朋友了。在上面邀请新朋友,或者他们已经拿到了这个 Bot。', ++ Share: '分享', ++ 'Share {name} with {who}': '把 {name} 分享给 {who}', ++ 'Sharing…': '正在分享…', ++ 'That Bot was removed from that home.': '那个 Bot 已从对方那里移除。', + 'Messages waiting for your approval': '等你批准的消息', + 'Waiting for approval': '等待批准', + // #3032: the four approval-card controls that were still drawn as bare English. diff --git a/patches/ds-bot/0008-client-bundle.patch b/patches/ds-bot/0008-client-bundle.patch index 293c2fdb6..676869613 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,106 @@ var ZH = { +@@ -78,21 +78,131 @@ var ZH = { " and ": "、", and: "和", "{count} members": "{count} 位成员", @@ -221,6 +221,31 @@ diff --git a/client.js b/client.js + "outside the tree": "不在树中", + Undo: "撤销", + "no longer shared": "已不再共享", ++ // #3114 cut 20: a Bot's Sharing page — the People-with-access card, its Auto-send switch and ++ // inline revoke question, and the share-with-a-friend card. ++ "One row per Bot. Default: nobody, Chief included.": "每行一个 Bot。默认谁都没有,包括 Chief。", ++ "One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.": "每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。", ++ "Nobody has this Bot yet. Copy an invite link above and send it to a friend.": "还没有人拿到这个 Bot。复制上面的邀请链接发给朋友。", ++ "Auto-send": "自动发送", ++ "Auto-send on": "自动发送已开", ++ "Auto-send off": "自动发送已关", ++ "Auto-send {name} → {who}": "{name} 发给 {who} 的消息自动发送", ++ "{name}’s replies to {who} go out without asking you first.": "{name} 发给 {who} 的回复不再先问你。", ++ Revoke: "撤销授权", ++ "Revoke {name}": "撤销 {name} 的授权", ++ "Revoking…": "正在撤销…", ++ "Revoke {who}? They lose this Bot.": "撤销 {who} 的授权?对方将失去这个 Bot。", ++ "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": "这个人", ++ "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…": "正在加载朋友…", ++ "No friends left to share with. Invite someone new above, or they already have this Bot.": "没有可分享的朋友了。在上面邀请新朋友,或者他们已经拿到了这个 Bot。", ++ Share: "分享", ++ "Share {name} with {who}": "把 {name} 分享给 {who}", ++ "Sharing…": "正在分享…", ++ "That Bot was removed from that home.": "那个 Bot 已从对方那里移除。", + "Messages waiting for your approval": "等你批准的消息", + "Waiting for approval": "等待批准", + // #3032: the four approval-card controls that were still drawn as bare English. 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 f1787dbe1..8921cc238 100644 --- a/patches/ds-bot/files/test/i18n-missing-entries.baseline.json +++ b/patches/ds-bot/files/test/i18n-missing-entries.baseline.json @@ -5,9 +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:Auto-send", - "plugins/social/client.js:Auto-send off", - "plugins/social/client.js:Auto-send on", "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.", @@ -37,13 +34,9 @@ "plugins/social/client.js:Leave#1", "plugins/social/client.js:Leave#2", "plugins/social/client.js:Link ready", - "plugins/social/client.js:Loading friends…", "plugins/social/client.js:Loading your Bots…", "plugins/social/client.js:Looking up that room…#1", "plugins/social/client.js:Looking up that room…#2", - "plugins/social/client.js:No friends left to share with. Invite someone new above, or they already have this Bot.", - "plugins/social/client.js:Nobody has this Bot yet. Copy an invite link above and send it to a friend.", - "plugins/social/client.js:One row per Bot. Default: nobody, Chief included.", "plugins/social/client.js:Past rooms", "plugins/social/client.js:Paste invite link or code", "plugins/social/client.js:Point the camera at a FlyBot room code.", @@ -54,27 +47,18 @@ "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:Revoke {}? They lose this Bot in {} room{}.", - "plugins/social/client.js:Revoke {}? They lose this Bot.", - "plugins/social/client.js:Revoke#1", - "plugins/social/client.js:Revoke#2", - "plugins/social/client.js:Revoking…", "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.", - "plugins/social/client.js:Share", "plugins/social/client.js:Share ", - "plugins/social/client.js:Share with a friend", - "plugins/social/client.js:Sharing…", "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 Bot was removed from that home.", "plugins/social/client.js:That is not a FlyBot room code. Ask for the 6-digit number instead.", "plugins/social/client.js:That is not an invite link. It looks like https://…/r/…", "plugins/social/client.js:That link cannot seat these Bots. Ask for a new one.", 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 764dbee01..62e6b87d0 100644 --- a/patches/ds-bot/files/test/i18n-template-draws.baseline.json +++ b/patches/ds-bot/files/test/i18n-template-draws.baseline.json @@ -4,28 +4,21 @@ "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 {} → {}", "plugins/social/client.js:Auto-send {}'s room messages", "plugins/social/client.js:Copy invite link for {}", "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: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:QR code for room number {}", "plugins/social/client.js:Remove {} from your list? {}", - "plugins/social/client.js:Revoke {}#1", - "plugins/social/client.js:Revoke {}#2", "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:Share {} with {}", "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:{}'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: {}", "plugins/timeline/client.js:Last {}", "plugins/timeline/client.js:Looking back: window ends at {}.", diff --git a/plugins/social/client.js b/plugins/social/client.js index 6c58c51ec..aaa04d9df 100644 --- a/plugins/social/client.js +++ b/plugins/social/client.js @@ -3652,7 +3652,7 @@ window.__ModuleLoader__.load({ const grants = view?.grants ?? [] // #2446: People with access is a read, so a read-only window keeps the list and its // Auto-send state, and only the two writes (Revoke, the Auto-send switch) go. - const note = readOnly ? 'One row per Bot. Default: nobody, Chief included.' : ACCESS_NOTE + const note = tr(readOnly ? 'One row per Bot. Default: nobody, Chief included.' : ACCESS_NOTE) // One Auto-send switch per person, however many of their Bots are rows (#995). const autoShown = new Set() // A room the grant rows already named must not come back under "This room only" (#955). @@ -3667,16 +3667,16 @@ window.__ModuleLoader__.load({ ) // Revoke drops the share and the rooms that use it. Ask once, inline, as Leave does (#1073). const revokeAsk = (grant) => { - const who = grant.name || grant.grantee || 'this person' + const who = grant.name || grant.grantee || tr('this person') const n = roomList(grant.rooms).length return n > 0 - ? `Revoke ${who}? They lose this Bot in ${n} room${n === 1 ? '' : 's'}.` - : `Revoke ${who}? They lose this Bot.` + ? tr(n === 1 ? 'Revoke {who}? They lose this Bot in {n} room.' : 'Revoke {who}? They lose this Bot in {n} rooms.', { who, n }) + : tr('Revoke {who}? They lose this Bot.', { who }) } return h('div', { className: 'fs fs-card', 'data-flybot': 'manage-access' }, h('div', { className: 'fs-name' }, tr('People with access')), h('div', { className: 'fs-hint fs-face-note' }, note), - grants.length === 0 ? h('div', { className: 'fs-hint' }, 'Nobody has this Bot yet. Copy an invite link above and send it to a friend.') : null, + grants.length === 0 ? h('div', { className: 'fs-hint' }, tr('Nobody has this Bot yet. Copy an invite link above and send it to a friend.')) : null, grants.map((grant) => { const grantUsage = roomHint('use', grant.rooms) const identity = accessIdentity(grant) @@ -3697,33 +3697,33 @@ window.__ModuleLoader__.load({ showAuto ? (readOnly ? h('span', { className: 'fs-hint fs-access-auto', 'data-flybot': 'access-auto-state', - title: `${bot.name || 'This Bot'}'s replies to ${grant.person || grant.home} go out without asking you first.`, - }, grant.autoSend === true ? 'Auto-send on' : 'Auto-send off') - : h('label', { className: 'fs-auto fs-access-auto', 'data-flybot': 'access-auto-send', title: `${bot.name || 'This Bot'}'s replies to ${grant.person || grant.home} go out without asking you first.` }, + title: tr('{name}’s replies to {who} go out without asking you first.', { name: bot.name || 'This Bot', who: grant.person || grant.home }), + }, grant.autoSend === true ? tr('Auto-send on') : tr('Auto-send off')) + : h('label', { className: 'fs-auto fs-access-auto', 'data-flybot': 'access-auto-send', title: tr('{name}’s replies to {who} go out without asking you first.', { name: bot.name || 'This Bot', who: grant.person || grant.home }) }, h('input', { type: 'checkbox', checked: grant.autoSend === true, disabled: Boolean(busy), - 'aria-label': `Auto-send ${bot.name || 'this Bot'} → ${grant.person || grant.home}`, + 'aria-label': tr('Auto-send {name} → {who}', { name: bot.name || 'this Bot', who: grant.person || grant.home }), onChange: e => { void toggleAutoSend(grant, e.target.checked) }, }), - 'Auto-send')) : null, + tr('Auto-send'))) : null, readOnly ? null : confirming ? h('span', { className: 'fs-leave-ask fs-access-ask', 'data-flybot': 'revoke-grant-confirm' }, h('span', { className: 'fs-hint' }, revokeAsk(grant)), h('button', { type: 'button', className: 'fs-btn fs-btn-sm', disabled: Boolean(busy), - 'data-flybot': 'revoke-grant-yes', 'aria-label': `Revoke ${grant.name || grant.grantee}`, + 'data-flybot': 'revoke-grant-yes', 'aria-label': tr('Revoke {name}', { name: grant.name || grant.grantee }), onClick: () => revoke(grant), - }, busy === grant.id ? 'Revoking…' : 'Revoke'), + }, busy === grant.id ? tr('Revoking…') : tr('Revoke')), h('button', { type: 'button', className: 'fs-btn fs-btn-sm', disabled: Boolean(busy), 'data-flybot': 'revoke-grant-no', onClick: () => setAsking(''), }, tr('Keep'))) : h('button', { type: 'button', className: 'fs-btn', disabled: Boolean(busy), - 'data-flybot': 'revoke-grant', 'aria-label': `Revoke ${grant.name || grant.grantee}`, + 'data-flybot': 'revoke-grant', 'aria-label': tr('Revoke {name}', { name: grant.name || grant.grantee }), onClick: () => setAsking(grantKey), - }, 'Revoke')) + }, tr('Revoke'))) }), roomOnlyUsage ? h('div', { className: 'fs-hint', title: roomOnlyUsage.title }, roomOnlyUsage.text) : null, error ? h('div', { className: 'fs-status', 'data-tone': 'error', role: 'status' }, error) : null) @@ -3915,7 +3915,7 @@ window.__ModuleLoader__.load({ // label over while its grant is still in flight and post two grants at once. if (busy) return // #1128: the button is disabled; a click that still arrives says why instead of posting a grant. - if (friend.removed === true) { setNote({ tone: 'error', text: friend.reason || 'That Bot was removed from that home.' }); return } + if (friend.removed === true) { setNote({ tone: 'error', text: friend.reason || tr('That Bot was removed from that home.') }); return } setBusy(friendKey(friend)) setNote(null) try { @@ -3942,11 +3942,11 @@ window.__ModuleLoader__.load({ const list = friends ?? [] const loading = friends === null return h('div', { className: 'fs fs-card', 'data-flybot': 'share-with-friend' }, - h('div', { className: 'fs-name' }, 'Share with a friend'), - h('div', { className: 'fs-hint' }, `One click shares ${bot.name || 'this Bot'} with someone you already know. No invite link. They can decline; you can Revoke in People with access.`), - loading ? h('div', { className: 'fs-hint' }, 'Loading friends…') : null, + h('div', { className: 'fs-name' }, tr('Share with a friend')), + h('div', { className: 'fs-hint' }, tr('One click shares {name} with someone you already know. No invite link. They can decline; you can Revoke in People with access.', { name: bot.name || 'this Bot' })), + loading ? h('div', { className: 'fs-hint' }, tr('Loading friends…')) : null, !loading && list.length === 0 && !listError - ? h('div', { className: 'fs-hint', 'data-flybot': 'share-with-friend-empty' }, 'No friends left to share with. Invite someone new above, or they already have this Bot.') + ? h('div', { className: 'fs-hint', 'data-flybot': 'share-with-friend-empty' }, tr('No friends left to share with. Invite someone new above, or they already have this Bot.')) : null, list.map(friend => h('div', { key: friendKey(friend), className: 'fs-line', 'data-flybot': 'share-friend-row' }, h('div', { className: 'fs-col' }, @@ -3955,7 +3955,7 @@ window.__ModuleLoader__.load({ ? h('span', { className: 'fs-sub' }, friend.handle || friend.home) : null, friend.removed === true - ? h('span', { className: 'fs-sub', 'data-flybot': 'share-friend-removed' }, friend.reason || 'That Bot was removed from that home.') + ? h('span', { className: 'fs-sub', 'data-flybot': 'share-friend-removed' }, friend.reason || tr('That Bot was removed from that home.')) : null), h('button', { type: 'button', @@ -3965,9 +3965,9 @@ window.__ModuleLoader__.load({ // #3062: one share at a time, so no row invites a click while any share is sending. disabled: !!busy || friend.removed === true, 'data-flybot': 'share-friend', - 'aria-label': `Share ${bot.name || 'this Bot'} with ${friend.name || friend.home}`, + 'aria-label': tr('Share {name} with {who}', { name: bot.name || 'this Bot', who: friend.name || friend.home }), onClick: () => { void share(friend) }, - }, busy === friendKey(friend) ? 'Sharing…' : 'Share'))), + }, busy === friendKey(friend) ? tr('Sharing…') : tr('Share')))), note ? h('div', { className: 'fs-status', 'data-tone': note.tone, 'data-flybot': 'share-note', role: 'status' }, note.text) : null, listError ? h('div', { className: 'fs-status', 'data-tone': 'error', 'data-flybot': 'share-list-error', role: 'status' }, listError, diff --git a/plugins/social/test/sharing-page-i18n.test.js b/plugins/social/test/sharing-page-i18n.test.js new file mode 100644 index 000000000..2b0e5c9a4 --- /dev/null +++ b/plugins/social/test/sharing-page-i18n.test.js @@ -0,0 +1,157 @@ +// #3114 cut 20: the two cards a Bot's Sharing page draws by default — People with access +// (`ManageAccess`) and Share with a friend (`ShareWithFriend`) — drew thirteen positions 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. Copy is read out of the rendered tree, where a translated draw and a +// string merely spelled like the dictionary's text differ. +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 (a card that reads a loaded list). +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: names and handles included, 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) +} +const bot = { id: 'b1', name: 'Mine' } +const grant = { id: 'g1', name: 'Eve', home: '@eve.home', person: 'Eve', grantee: '@eve.home', autoSend: false, rooms: [] } +const empty = { grants: [], rooms: [] } +test('#3114 cut 20: the People-with-access card speaks the window’s language', () => { + const app = loadApp(zhWindow, [{ grants: [grant], rooms: [] }]) + const nodes = app.ManageAccess({ bot, onGrants: () => {} }) + const drawn = draw(nodes) + // Every position this card draws is a dictionary entry, so a missing one names itself here. + for (const key of [ + 'Auto-send', 'Auto-send on', 'Auto-send off', 'Auto-send {name} → {who}', + '{name}’s replies to {who} go out without asking you first.', 'Revoke', 'Revoke {name}', 'Revoking…', + 'Revoke {who}? They lose this Bot.', 'Revoke {who}? They lose this Bot in {n} room.', + 'Revoke {who}? They lose this Bot in {n} rooms.', 'this person', + 'One row per Bot. Default: nobody, Chief included.', + 'One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.', + 'Nobody has this Bot yet. Copy an invite link above and send it to a friend.', + ]) assert.ok(zh[key], `expected ${zh[key]} (${key}), saw ${JSON.stringify(drawn)}`) + assert.deepEqual(drawn, ['可访问的人', '每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。', 'Eve', '@eve.home', '自动发送', '撤销授权']) + assert.equal(button(nodes, 'access-auto-state'), undefined, 'a writable card draws the switch, not the state') + assert.equal(button(nodes, 'access-auto-send').children[0].props['aria-label'], 'Mine 发给 Eve 的消息自动发送') + assert.equal(button(nodes, 'access-auto-send').props.title, 'Mine 发给 Eve 的回复不再先问你。') + assert.equal(button(nodes, 'revoke-grant').props['aria-label'], '撤销 Eve 的授权') + + // Read-only drops the two writes and keeps the list, its note and the Auto-send state. + const locked = loadApp(zhWindow, [{ grants: [{ ...grant, autoSend: true }], rooms: [] }]).ManageAccess({ bot, readOnly: true }) + assert.deepEqual(draw(locked), ['可访问的人', '每行一个 Bot。默认谁都没有,包括 Chief。', 'Eve', '@eve.home', '自动发送已开']) + // Nobody holds the Bot yet. + const none = loadApp(zhWindow, [empty]).ManageAccess({ bot }) + assert.deepEqual(draw(none), ['可访问的人', '每行一个 Bot。撤销其中一个不影响其他。默认谁都没有,包括 Chief。', '还没有人拿到这个 Bot。复制上面的邀请链接发给朋友。']) + // The inline revoke question counts the rooms the grant reaches, and the busy label follows too. + const asked = loadApp(zhWindow, [{ grants: [{ ...grant, rooms: [{ id: 'r1', name: 'Den' }] }], rooms: [] }, 'g1', '', 'g1']).ManageAccess({ bot }) + const askedDraw = draw(asked) + assert.ok(askedDraw.includes('撤销 Eve 的授权?对方将在 1 个房间里失去这个 Bot。'), `the question reads: ${askedDraw.join(' | ')}`) + assert.ok(askedDraw.includes('正在撤销…'), 'the busy button follows the window too') + assert.equal(button(asked, 'revoke-grant-yes').props['aria-label'], '撤销 Eve 的授权') + // `'this person'` is a dictionary entry of its own: a grant naming nobody reads Chinese. + const anon = loadApp(zhWindow, [{ grants: [{ id: 'g2', home: '@x.home', rooms: [] }], rooms: [] }, '', '', 'g2']).ManageAccess({ bot }) + assert.ok(draw(anon).some(text => text.startsWith('撤销 这个人 的授权')), 'the fallback noun is Chinese too') +}) + +test('#3114 cut 20: the share-with-a-friend card speaks the window’s language', () => { + const app = loadApp(zhWindow, [[]]) + const nodes = app.ShareWithFriend({ bot }) + const drawn = draw(nodes) + for (const key of [ + '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.', + 'Loading friends…', 'No friends left to share with. Invite someone new above, or they already have this Bot.', + 'Share', 'Share {name} with {who}', 'Sharing…', 'That Bot was removed from that home.', + ]) assert.ok(zh[key], `expected ${zh[key]} (${key}), saw ${JSON.stringify(drawn)}`) + assert.deepEqual(drawn, ['分享给朋友', '一键把 Mine 分享给你已经认识的人,不需要邀请链接。对方可以拒绝,你也可以在「可访问的人」里撤销。', '没有可分享的朋友了。在上面邀请新朋友,或者他们已经拿到了这个 Bot。']) + // A list still loading says so, and a row says who it shares with. + const loading = loadApp(zhWindow, []).ShareWithFriend({ bot }) + assert.deepEqual(draw(loading).slice(-1), ['正在加载朋友…']) + const friend = { peerBotId: 'p1', name: 'Helper', home: '@helper.eve.home', handle: '@helper' } + const row = loadApp(zhWindow, [[friend]]).ShareWithFriend({ bot }) + assert.deepEqual(draw(row).slice(-3), ['Helper', '@helper', '分享']) + assert.equal(button(row, 'share-friend').props['aria-label'], '把 Mine 分享给 Helper') + // A row whose Bot left that home keeps its reason in the window's language, and one in flight says so. + const gone = loadApp(zhWindow, [[{ ...friend, removed: true, reason: undefined }]]).ShareWithFriend({ bot }) + assert.ok(draw(gone).includes('那个 Bot 已从对方那里移除。'), `the removed row reads: ${draw(gone).join(' | ')}`) + const busy = loadApp(zhWindow, [[friend], 'p1']).ShareWithFriend({ bot }) + assert.equal(button(busy, 'share-friend').children.join(''), '正在分享…') +}) + +// 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', [ + 'One row per Bot. Default: nobody, Chief included.', + 'Nobody has this Bot yet. Copy an invite link above and send it to a friend.', + 'Auto-send', 'Auto-send on', 'Auto-send off', 'Revoking…', 'Revoke#1', 'Revoke#2', + 'Revoke {}? They lose this Bot.', 'Revoke {}? They lose this Bot in {} room{}.', + 'Share with a friend', 'Loading friends…', 'Sharing…', 'That Bot was removed from that home.', + 'No friends left to share with. Invite someone new above, or they already have this Bot.', + ]], + ['i18n-template-draws.baseline.json', [ + 'Revoke {}#1', 'Revoke {}#2', 'Share {} with {}', 'Auto-send {} → {}', + "{}'s replies to {} go out without asking you first.#1", + "{}'s replies to {} go out without asking you first.#2", + ]], +] +const entriesOf = file => JSON.parse(readFileSync(new URL(`../../../core/test/${file}`, import.meta.url), 'utf8')).entries + +test('#3114 cut 20: the three baselines lose these draws', () => { + 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 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]) + + // 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 bare = loadApp(bareWindow, [{ grants: [grant], rooms: [] }]) + assert.deepEqual(draw(bare.ManageAccess({ bot })), ['People with access', 'One row per Bot. Revoke one without affecting the rest. Default: nobody, Chief included.', 'Eve', '@eve.home', 'Auto-send', 'Revoke']) + assert.deepEqual(draw(loadApp(bareWindow, [[]]).ShareWithFriend({ bot })), ['Share with a friend', 'One click shares Mine with someone you already know. No invite link. They can decline; you can Revoke in People with access.', 'No friends left to share with. Invite someone new above, or they already have this Bot.']) + // People with access is reused, never added twice. + assert.equal(zh['People with access'], '可访问的人') +})