Files
usage-zh/zh-map.mjs
T
cat-shark 50740b4d08 feat: /usage 用量面板中文化(上游 0.10.2)
基于 @tmustier/pi-usage-extension 0.10.2(github.com/tmustier/pi-extensions 的
usage-extension/),仅改文案与 3 处中文宽度/排版补丁。

- zh-map.mjs:100 条词表(103 处替换),覆盖视图/周期/表头/快捷键/加载/洞察全部文案
- apply-zh.mjs:幂等应用器,上游改文案时报 MISS 而非静默漏译
- 本地补丁:x 轴日期改 ASCII M/D、分组横线用 visibleWidth、中文括号前不补空格
- 数据层:辅助用量伪渠道改 工具/摘要,CACHE_VERSION 6→7(名字会 intern 进缓存)
- 保持英文:CSV 表头、JSON 键名、导出文件名,避免下游表格/脚本失配
- scripts/:渲染与数据/导出冒烟脚本
2026-11-18 14:46:30 +08:00

242 lines
14 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 汉化词表:英文原文 → 中文。apply-zh.mjs 用它对上游文件做精确替换。
// 规则:每条 en 必须在目标文件中至少出现一次;0 命中会报错(上游改文案时提醒人工跟进)。
// en 尽量带上足够上下文(含引号与字段名),避免误伤代码里的同名字符串。
export const MAP = {
"index.ts": [
// ---- 视图 / 周期 / 列名 ----
['graph: "Graphs",', 'graph: "图表",'],
['table: "Table",', 'table: "表格",'],
['insights: "Insights",', 'insights: "洞察",'],
['label: "Sessions",', 'label: "会话",'],
['label: "Msgs",', 'label: "消息",'],
['label: "Cost",', 'label: "花费",'],
['label: "Tokens",', 'label: "Token",'],
['label: "↑In",', 'label: "↑输入",'],
['label: "↓Out",', 'label: "↓输出",'],
['label: "Cache",', 'label: "缓存",'],
['today: "Today",', 'today: "今天",'],
['thisWeek: "This Week",', 'thisWeek: "本周",'],
['lastWeek: "Last Week",', 'lastWeek: "上周",'],
['thisMonth: "This Month",', 'thisMonth: "本月",'],
['last30Days: "Last 30 Days",', 'last30Days: "近30天",'],
['allTime: "All Time",', 'allTime: "累计",'],
// ---- 标题 / 图例模式 ----
['th.bold("Usage")', 'th.bold("用量")'],
['this.graphCumulative ? "Cumulative" : "Per bucket"', 'this.graphCumulative ? "累计" : "分桶"'],
// ---- 空态 / 提示 ----
['" No usage data for this period"', '" 本期无用量数据"'],
['" Nothing matches the current filter — [a] resets"', '" 没有匹配当前筛选的行 — [a] 重置"'],
['"[Enter] keep · [Esc] clear"', '"[Enter] 保留 · [Esc] 清除"'],
['`filter: “${this.tableFilter.trim()}”`', '`筛选:“${this.tableFilter.trim()}”`'],
['`${this.tableHidden.size} hidden`', '`已隐藏 ${this.tableHidden.size} 项`'],
['totals reflect this slice · [a] reset', '合计仅反映此切片 · [a] 重置'],
['"Compact view. Widen the terminal for more columns."', '"紧凑视图。拉宽终端可显示更多列。"'],
// ---- 表头 / 合计 ----
['"Provider / Model"', '"渠道 / 模型"'],
['th.bold("Total")', 'th.bold("合计")'],
// ---- 表格底部公式说明 ----
['"Tokens = Input + Output + CacheWrite · ↑In = Input + CacheWrite (as of 0.2.0)"', '"Token = 输入 + 输出 + 缓存写入 · ↑输入 = 输入 + 缓存写入 (自 0.2.0)"'],
['"Tokens = In + Out + CacheWrite · ↑In = In + CacheWrite (v0.2.0+)"', '"Token = 输入 + 输出 + 缓存写 · ↑输入 = 输入 + 缓存写 (v0.2.0+)"'],
['"Tokens & ↑In include CacheWrite (v0.2.0+)"', '"Token 与 ↑输入 含缓存写入 (v0.2.0+)"'],
['"Incl. CacheWrite (v0.2.0+)"', '"含缓存写入 (v0.2.0+)"'],
// ---- 洞察页 ----
['th.bold("What\'s contributing to your cost?")', 'th.bold("你的花费都花在哪了?")'],
[
'"Approximate, based on local sessions on this machine (these are independent and don\'t sum to 100%)."',
'"近似估算,仅统计本机本地会话(各项相互独立,合计不等于 100%)。"',
],
['" No usage recorded for this period."', '" 本期无用量记录。"'],
['" No cost data recorded for this period."', '" 本期无花费记录。"'],
['" Nothing notable for this period."', '" 本期没有值得注意的项。"'],
['sectionHeader("Where it went", "accent")', 'sectionHeader("花在哪了", "accent")'],
['sectionHeader("Worth attention", "warning")', 'sectionHeader("值得注意", "warning")'],
['"no waste patterns flagged for this period"', '"本期未发现浪费模式"'],
// 中文括号里的"本期 x%",正则同步改(用于把括号部分渲染成暗色)
['/^(.*?)\\s*(\\(\\d[\\d.,]*% of this period\\))$/', '/^(.*?)\\s*((本期 [\\d.,]+%))$/'],
// ---- 导出回执 ----
['`Saved ${shown}`', '`已保存 ${shown}`'],
['`Export failed: ${err instanceof Error ? err.message : String(err)}`', '`导出失败:${err instanceof Error ? err.message : String(err)}`'],
// ---- 底部快捷键提示 ----
[
'"[Tab/←→] period [m] metric [g] group [c] cumulative [↑↓/Enter] filter [a] all [e] export [v] view [q] close"',
'"[Tab/←→] 周期 [m] 指标 [g] 分组 [c] 累计 [↑↓/Enter] 筛选 [a] 全显 [e] 导出 [v] 视图 [q] 关闭"',
],
[
'"[Tab] period [m] metric [g] group [c] cumul [↑↓/Enter] filter [e] export [v] view [q] close"',
'"[Tab] 周期 [m] 指标 [g] 分组 [c] 累计 [↑↓/Enter] 筛选 [e] 导出 [v] 视图 [q] 关闭"',
],
['"[m] metric [g] group [c] cumul [↑↓] filter [q] close"', '"[m] 指标 [g] 分组 [c] 累计 [↑↓] 筛选 [q] 关闭"'],
['"[q] close"', '"[q] 关闭"'],
['"[Tab/←→] period [e] export [v] view [q] close"', '"[Tab/←→] 周期 [e] 导出 [v] 视图 [q] 关闭"'],
['"[Tab] period [e] export [v] view [q] close"', '"[Tab] 周期 [e] 导出 [v] 视图 [q] 关闭"'],
['"[v] view [q] close"', '"[v] 视图 [q] 关闭"'],
[
'"[Tab/←→] period [↑↓] select [Enter] expand [/] filter [x] hide [a] all [e] export [v] view [q] close"',
'"[Tab/←→] 周期 [↑↓] 选择 [Enter] 展开 [/] 筛选 [x] 隐藏 [a] 全显 [e] 导出 [v] 视图 [q] 关闭"',
],
[
'"[Tab] period [↑↓] select [Enter] expand [/] filter [x] hide [e] export [v] view [q] close"',
'"[Tab] 周期 [↑↓] 选择 [Enter] 展开 [/] 筛选 [x] 隐藏 [e] 导出 [v] 视图 [q] 关闭"',
],
[
'"[↑↓] select [Enter] expand [/] filter [x] hide [v] view [q] close"',
'"[↑↓] 选择 [Enter] 展开 [/] 筛选 [x] 隐藏 [v] 视图 [q] 关闭"',
],
['"[↑↓] select [/] [x] [v] [q]"', '"[↑↓] 选择 [/] [x] [v] [q]"'],
['"[↑↓] select [q] close"', '"[↑↓] 选择 [q] 关闭"'],
// ---- 加载与进度 ----
['"Loading Usage..."', '"正在统计用量..."'],
[
'`${p.filesParsed.toLocaleString()}/${p.filesToParse.toLocaleString()} files`',
'`${p.filesParsed.toLocaleString()}/${p.filesToParse.toLocaleString()} 个文件`',
],
['` since ${formatSinceDate(p.sinceMs)}`', '`(自 ${formatSinceDate(p.sinceMs)})`'],
['`Updating your usage history${since}… (${files})`', '`正在更新用量历史${since}…(${files})`'],
[
'`Rebuilding your usage history — the cache format changed… (${files})`',
'`正在重建用量历史 — 缓存格式已变更…(${files})`',
],
['`Building your usage history for the first time… (${files})`', '`正在首次构建用量历史…(${files})`'],
// ---- 命令描述 ----
['description: "Show usage statistics dashboard",', 'description: "显示用量统计面板",'],
],
"graph.ts": [
['cost: "cost",', 'cost: "花费",'],
['tokens: "tokens",', 'tokens: "Token",'],
['messages: "messages",', 'messages: "消息数",'],
['reasoning: "reasoning tokens",', 'reasoning: "推理 Token",'],
['provider: "by provider",', 'provider: "按渠道",'],
['model: "by model",', 'model: "按模型",'],
['thinking: "by thinking level",', 'thinking: "按思考等级",'],
['total: "total only",', 'total: "仅合计",'],
['label: "Total",', 'label: "合计",'],
['label: `other (${merged.length})`', 'label: `其他 (${merged.length})`'],
['thinkingLevel === "" ? "unknown" : thinkingLevel', 'thinkingLevel === "" ? "未知" : thinkingLevel'],
],
"data.ts": [
// 辅助用量(工具/摘要)伪渠道名会写入缓存,故同时 bump CACHE_VERSION 强制重建一次
['export const AUXILIARY_PROVIDER = "Tools";', 'export const AUXILIARY_PROVIDER = "工具";'],
['export const AUXILIARY_MODEL = "summaries";', 'export const AUXILIARY_MODEL = "摘要";'],
['export const AUXILIARY_THINKING_LEVEL = "Tools/summaries";', 'export const AUXILIARY_THINKING_LEVEL = "工具/摘要";'],
['const CACHE_VERSION = 6;', 'const CACHE_VERSION = 7;'],
[
'raw.auxiliaryCost > 0 ? "assistant-message cost" : "this period";',
'raw.auxiliaryCost > 0 ? "助手消息花费" : "本期花费";',
],
// --- 告警:停顿后恢复 ---
[
'headline: `spent resuming conversations after a break (${fmtPercent(ttlPct)} of ${assistantPctLabel})`',
'headline: `花在停顿后恢复会话上(占${assistantPctLabel}的 ${fmtPercent(ttlPct)})`',
],
[
'"Sent context is only reusable for a few minutes. After a longer pause, the next message pays to send the whole conversation again. Replying while a session is fresh avoids this."',
'"已发送的上下文只有几分钟可复用。停顿较久后,下一条消息要按全价重发整段对话。趁会话还新鲜时继续回复即可避免。"',
],
// --- 告警:中途换模型 ---
[
'headline: `spent switching models mid-conversation (${fmtPercent(switchPct)} of ${assistantPctLabel})`',
'headline: `花在对话中途切换模型上(占${assistantPctLabel}的 ${fmtPercent(switchPct)})`',
],
[
'"Changing model re-sends the whole conversation at full price — the previous model\'s saved context doesn\'t transfer. Switching between tasks instead of mid-conversation avoids this."',
'"换模型会按全价重发整段对话 — 上一个模型存下的上下文不会转移。改为在两个任务之间切换即可避免。"',
],
// --- 告警:中途重发前缀 ---
[
'headline: `spent re-sending conversations mid-session (${fmtPercent(prefixPct)} of ${assistantPctLabel})`',
'headline: `花在会话中途重发上下文上(占${assistantPctLabel}的 ${fmtPercent(prefixPct)})`',
],
[
'"These messages paid full price for context that had already been sent — with no break, compaction, or model switch to explain it. Usually a tool or workflow is restarting or rewriting conversations. Worth a look if it stays high."',
'"这些消息为已经发过的上下文又付了一次全价 — 且没有停顿、压缩或换模型可以解释。通常是某个工具或流程在重启、重写对话。若长期偏高值得排查。"',
],
// --- 告警:花费集中 ---
[
'headline: `came from just ${TOP_SESSION_COUNT} of your ${raw.sessionCosts.size} sessions (${fmtPercent(topPct)} of this period)`',
'headline: `只来自你 ${raw.sessionCosts.size} 个会话中的 ${TOP_SESSION_COUNT} 个(本期 ${fmtPercent(topPct)})`',
],
[
'"A handful of sessions drove most of the spend. The graph view can show what they were doing."',
'"少数几个会话吃掉了大部分花费。图表视图可以看出它们在做什么。"',
],
// --- 告警:开场消息开销 ---
[
'headline: `spent on the opening message of new sessions (${fmtPercent(upfrontPct)} of ${assistantPctLabel})`',
'headline: `花在新会话的首条消息上(占${assistantPctLabel}的 ${fmtPercent(upfrontPct)})`',
],
[
'"A session\'s first message sends everything from scratch. Fewer, longer sessions cut this overhead."',
'"会话的第一条消息要从零发送全部内容。更少、更长的会话可以降低这部分开销。"',
],
// --- 告警:缓存复用倍数偏低 ---
[
'headline: "tokens reused from history for every token paid at full price"',
'headline: "历史复用倍数(每付一次全价的 token)"',
],
[
'"Typical interactive use reuses 10× or more. A low number means conversations keep being sent from scratch — look for workflows that restart sessions."',
'"典型交互式用法能复用 10× 以上。数值偏低说明对话在反复从零发送 — 找找有没有会重启会话的流程。"',
],
// --- 结构:工具/摘要用量 ---
[
'headline: "of your cost came from usage reported by tools and conversation summaries"',
'headline: "的花费来自工具与对话摘要上报的用量"',
],
[
'"Pi records this separately because it cannot be attributed reliably to a specific provider and model."',
'"Pi 单独记录这部分,因为它无法可靠归属到某个具体渠道和模型。"',
],
// --- 结构:长上下文税 ---
[
'` — ${fmtMoney(avgHigh)}/msg vs ${fmtMoney(avgLow)} under ${formatThresholdTokens(CTX_LOW_THRESHOLD)}`',
'` — 每条 ${fmtMoney(avgHigh)},而低于 ${formatThresholdTokens(CTX_LOW_THRESHOLD)} 时为 ${fmtMoney(avgLow)}`',
],
[
'headline: `of your ${raw.auxiliaryCost > 0 ? "assistant-message cost" : "cost"} came from messages with ≥${formatThresholdTokens(CTX_TAX_THRESHOLD)} tokens loaded${cmp}`',
'headline: `的${raw.auxiliaryCost > 0 ? "助手消息花费" : "花费"}来自载入 ≥${formatThresholdTokens(CTX_TAX_THRESHOLD)} token 的消息${cmp}`',
],
[
'"Long conversations cost more per message. /compact mid-task and /clear between tasks keep them lean."',
'"长对话每条消息都更贵。任务中段 /compact、任务之间 /clear 可以让对话保持精简。"',
],
// --- 结构:项目分布 ---
[
'headline: `of your cost was ${top[0]![0]}${rest ? ` — then ${rest}` : ""}`',
'headline: `的花费来自 ${top[0]![0]}${rest ? ` — 其次是 ${rest}` : ""}`',
],
// --- 结构:隐藏推理占比 ---
[
'headline: "of your output tokens were hidden reasoning"',
'headline: "的输出 token 属于隐藏推理"',
],
[
'"Models charge for their behind-the-scenes thinking as output tokens. pi records this only from 0.80.3 (June 2026), so older periods understate it."',
'"模型会按输出 token 收取后台思考的费用。pi 自 0.80.3(2026 年 6 月)起才记录此项,更早的周期会偏低。"',
],
// --- 结构:花费趋势 ---
[
'"Spending is up against your own baseline — the graph view shows what changed."',
'"花费相对你自己的基线在上升 — 图表视图可以看出变化来自哪里。"',
],
['"Spending is well below your recent baseline."', '"花费明显低于你近期的基线。"'],
[
'headline: `your last 7 days (${fmtMoney(trend.last7Cost)}) vs your prior 4-week pace (${fmtMoney(trend.priorWeeklyPace)}/wk)`',
'headline: `最近 7 天(${fmtMoney(trend.last7Cost)})对比此前 4 周的周均(${fmtMoney(trend.priorWeeklyPace)}/周)`',
],
],
};