From eb779ce92a9a5a4c77dd09a35fa8dfbe8c140df5 Mon Sep 17 00:00:00 2001 From: yetone Date: Tue, 3 Nov 2026 10:11:15 +0800 Subject: [PATCH] gui: the tray icon's tooltip is in magpie's language (yi_time) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit yi_time in #feedback: magpie set to Chinese on Windows, and the tray icon's hover tooltip said "Today: 121K tokens (2.9K in · 180 out · 118K cached)" and "3 requests" in English. The tray menu already followed magpie's language (trayLang, #301); the tooltip's words were hard-coded English in trayusage.go. Now every tooltip is in trayLang(settings.Lang, systemLang), on Windows, macOS and Linux alike. That covers trayIdleTip, magpie's totals (trayTotalCard), and each subscription card (trayCardText: its use or what is left, the pace, when it resets, until's d/h/m, "as of …"). The words are in trayWords beside the menu's, for zh, zh-TW, ja and de; English stays the key and the fallback. A window's name and an error are still the card's own. A change of language in Settings now also refreshes the tooltip (onTrayUsage); before, only the menu was relabelled. The test-only trayUsageText and trayUsageView stay in English, so the existing tests keep their strings. Test: TestTrayTooltipFollowsMagpiesLanguage. - yi_time's own numbers in zh: "magpie\n今天:121K token(输入 2.9K · 输出 180 · 缓存 118K)\n3 个请求". - The same numbers in en are unchanged. - Covers the total card and a card's used, left, reset and as-of. - For zh, zh-TW, ja and de, no English word in the idle, totals, card (with pace) or combined tooltips. Run at this head (rebased on 5573f7923): - mote: gofmt -l clean; CGO_ENABLED=0 GOOS=linux go vet -tags nogui and GOOS=windows go vet of ./internal/gui ok. - mote: go test ./internal/gui. Everything passes except TestMainWindowCorners/macOS_26_SDK, which is #3949 (red on mote's macOS 27, not touched here). - Windows (xiaomi-gpu, win-run): go test -run Tray ./internal/gui ok. Broken by hand: with the tooltip words taken out of trayWords, the test goes red. Its zh output is then exactly the old English tooltip. Not tried: - The real tray on Windows, hovering the icon. - The watch loop's choice of language has no test of its own. Passing "en" there would not go red. --- docs/subsystems/gui-shell.md | 2 +- internal/gui/api.go | 7 +- internal/gui/trayidle_test.go | 4 +- internal/gui/traymenu.go | 90 ++++++++++++++++++++++++- internal/gui/traynumber_test.go | 2 +- internal/gui/traytip_lang_test.go | 77 +++++++++++++++++++++ internal/gui/trayusage.go | 89 ++++++++++++------------ internal/gui/trayusage_nocost_test.go | 8 +-- internal/gui/trayusage_pick_test.go | 10 +-- internal/gui/trayusage_shared_test.go | 14 ++-- internal/gui/trayusage_total_test.go | 12 ++-- internal/gui/trayusage_tray.go | 6 +- internal/gui/traywindows_darwin_test.go | 4 +- 13 files changed, 247 insertions(+), 78 deletions(-) create mode 100644 internal/gui/traytip_lang_test.go diff --git a/docs/subsystems/gui-shell.md b/docs/subsystems/gui-shell.md index 2470fb172..78c8370d4 100644 --- a/docs/subsystems/gui-shell.md +++ b/docs/subsystems/gui-shell.md @@ -550,7 +550,7 @@ covers it in both engines, every language and a narrow window. - The requests magpie makes by itself (a routing classifier's, a web search's, an image description's) are told apart from the agents' on the Usage page (#1839): magpie's row among the agents and its rows in the ledger carry a "magpie's own" mark (`ownBadge`), an account's, key's or model's row adds "{n} by magpie itself" from the summary's `own`, and an account's card says how many of the period's requests were magpie's own (`ownLine`, drawn again once the summary comes after the allowances). See `own-requests.test.cjs` and `TestSummaryCountsMagpiesOwnCallsApart`. - Opening the allowances is asking to see them (#1588, `quotasOpened` in `app.js`): the Usage page from the nav or its Overview tab picked, the window brought back to the front on the Overview, the tray panel's Allowances tab picked or the panel brought up on it, and a menu bar cell clicked each load `usage/quotas?asked=1`, as Refresh now does. An asked read makes the backend read every account again (`AskClaudeUsage`), so an opening within 30s (`QUOTAS_OPEN_GAP`) of the last asked read sends an ordinary read instead, which joins one on its way; Refresh now always asks. A panel page loaded while it is put away (hidden, or without focus) doesn't ask. The timed refresh is unchanged and never asks. See `allowance-open-read.test.cjs`. - The menu bar can show magpie's own totals beside the allowances (#1984): `usage:today` and `usage:7d` in `settings.TrayUsages`, offered after the cards in the same picker. `trayUsageCards` sums them with `usage.QueryPage(p, Filter{}, 0, 1).Sum` (the Requests tab's and the panel's cached ledger sum, gateway and session-file calls together) and asks no vendor when only totals are picked; `trayTotalCard` makes every token (in, out and cache, as `allTokens`), marked `Σ` so it doesn't read as the input, over the cost in Settings' currency, `+` when some calls had no price, the cost row left out when none had one. The Mac draws them as plain cells, the bird beside them saying whose. A click opens the Requests tab at the period (`quotaView`, `?tab=requests&period=`) or the panel's Usage tab (`panelUseFocus`). No 3-day total: the Usage page has no such window. See `TestTrayTotals` and `tray-totals.test.cjs`. Settings › *Menu bar cost* (`settings.TrayNoCost`, on by default, on every OS, per computer through `KeepOwn`) turned off leaves the money out (BussanQ on Discord): `trayMoney` drops the total's cost and its count of unpriced calls before `trayTotalCard` and the no-card tooltip `trayIdleTip` see it, so the cards, their tooltip and the idle tooltip say the tokens and requests alone. A relay's or subscription's balance card is money itself and stays. See `TestTrayNoCost` and `tray-cost.test.cjs`. -- The tray's icon is the bird alone where the bar's other icons are glyphs: the Mac's menu bar takes `tray.png` as a template image, and a Linux bar (StatusNotifierItem `IconPixmap`) gets the same silhouette in one colour on transparency (`trayIconFor`, `linuxTrayIcon` in [`trayglyph.go`](../../internal/gui/trayglyph.go)), so a bar that tints its icons by their alpha tints the bird, not a tile (ylorn on Discord). A bar that doesn't tint shows it light, or dark when the portal's `org.freedesktop.appearance` `color-scheme` prefers light (`traySchemeLight`), and it is drawn again when that changes (`watchTrayScheme`). No `IconName` is set: a host that found a `-symbolic` name and drew it untinted would show a black bird on a dark bar, with no pixmap to fall back on. Windows' tray keeps the app's coloured icon, unless a card is in the menu bar: Windows' notification area shows no text beside an icon, so the icon itself is the first card's figure (Benjaminliang_1 on X; `trayIconFigure`, `trayNumberIcon` in [`traynumber.go`](../../internal/gui/traynumber.go)). It is the first row of the first card whose first row is a percentage, used or left as Allowance display has it, through *Menu bar windows*' pick, its digits alone, drawn in Segoe UI Semibold (Go's bold where the font can't be read) at `SM_CXSMICON`, white on a dark taskbar and near black on a light one, as tall as fits with a pixel above and below, centred by its ink, and three digits narrowed into the square. A balance or magpie's totals are skipped for the next card; with none the icon is the bird. It is drawn again when the figure, the icon size or the taskbar's theme changes (`SystemThemeChanged` wakes the loop); the tooltip still says every card. Settings › *Tray icon number* (`settings.TrayNoNumber`, Windows' alone, on by default) keeps the bird when off. One icon is set for the current theme, not a light and a dark one: Wails' Windows tray shares one handle between them. Linux keeps its label and tooltip; the Mac its cells. See `TestTrayIconFigure`, `TestTrayNumberIcon` and `tray-windows.test.cjs`. With no cards in the menu bar the tooltip is magpie over today's total (`trayIdleTip`: every token, split into input, output and cache as the today card's tooltip is, then the cost and the requests), brought up to date with the cards' refresh; the tray's menu stays Open, the version and Quit. Wails sets the tooltip only on Windows: on Linux `setTrayTip` sets the StatusNotifierItem's `ToolTip` and sends `NewToolTip` ([`traytip_linux.go`](../../internal/gui/traytip_linux.go)), and on the Mac it is the status item's button's `toolTip` (`trayTipNative` in [`trayimage_darwin.go`](../../internal/gui/trayimage_darwin.go); NextCommit on Discord: no hover there showed anything). See `TestTrayIconPerOS`, `TestTrayIdleTip` and `TestMacTrayTipIsSet`. +- The tray's icon is the bird alone where the bar's other icons are glyphs: the Mac's menu bar takes `tray.png` as a template image, and a Linux bar (StatusNotifierItem `IconPixmap`) gets the same silhouette in one colour on transparency (`trayIconFor`, `linuxTrayIcon` in [`trayglyph.go`](../../internal/gui/trayglyph.go)), so a bar that tints its icons by their alpha tints the bird, not a tile (ylorn on Discord). A bar that doesn't tint shows it light, or dark when the portal's `org.freedesktop.appearance` `color-scheme` prefers light (`traySchemeLight`), and it is drawn again when that changes (`watchTrayScheme`). No `IconName` is set: a host that found a `-symbolic` name and drew it untinted would show a black bird on a dark bar, with no pixmap to fall back on. Windows' tray keeps the app's coloured icon, unless a card is in the menu bar: Windows' notification area shows no text beside an icon, so the icon itself is the first card's figure (Benjaminliang_1 on X; `trayIconFigure`, `trayNumberIcon` in [`traynumber.go`](../../internal/gui/traynumber.go)). It is the first row of the first card whose first row is a percentage, used or left as Allowance display has it, through *Menu bar windows*' pick, its digits alone, drawn in Segoe UI Semibold (Go's bold where the font can't be read) at `SM_CXSMICON`, white on a dark taskbar and near black on a light one, as tall as fits with a pixel above and below, centred by its ink, and three digits narrowed into the square. A balance or magpie's totals are skipped for the next card; with none the icon is the bird. It is drawn again when the figure, the icon size or the taskbar's theme changes (`SystemThemeChanged` wakes the loop); the tooltip still says every card. Settings › *Tray icon number* (`settings.TrayNoNumber`, Windows' alone, on by default) keeps the bird when off. One icon is set for the current theme, not a light and a dark one: Wails' Windows tray shares one handle between them. Linux keeps its label and tooltip; the Mac its cells. See `TestTrayIconFigure`, `TestTrayNumberIcon` and `tray-windows.test.cjs`. With no cards in the menu bar the tooltip is magpie over today's total (`trayIdleTip`: every token, split into input, output and cache as the today card's tooltip is, then the cost and the requests), brought up to date with the cards' refresh; the tray's menu stays Open, the version and Quit. Wails sets the tooltip only on Windows: on Linux `setTrayTip` sets the StatusNotifierItem's `ToolTip` and sends `NewToolTip` ([`traytip_linux.go`](../../internal/gui/traytip_linux.go)), and on the Mac it is the status item's button's `toolTip` (`trayTipNative` in [`trayimage_darwin.go`](../../internal/gui/trayimage_darwin.go); NextCommit on Discord: no hover there showed anything). See `TestTrayIconPerOS`, `TestTrayIdleTip` and `TestMacTrayTipIsSet`. Every tooltip, the idle one, magpie's totals' and each card's (its use or what is left, the pace, when it resets, "as of …"), is in magpie's language, as the tray menu is: `watchTrayUsage` passes `trayLang(settings.Lang, systemLang)` to `trayCardsView`, `trayUsageCards` and `trayIdleTip`, whose words are in `trayWords` beside the menu's, and a change of language in Settings refreshes it at once (`onTrayUsage`). A window's name and an error are the card's own (yi_time on Discord: English on a Windows magpie set to Chinese; `TestTrayTooltipFollowsMagpiesLanguage`). - A window's Pace is a number on its card's reset line (fflake33 on Discord): the share used less the share of the window gone by, in points, "Pace +12%" over an even pace and "−8%" under it, turned with the meter when it shows what is left, amber while more is used than an even pace would have (`quotaPace`, `paceLine`). The window's start is the gateway's, `startsAt` from `provider.WithWindowStarts` (its reset less its span, `QuotaWindow.Bounds`); a window whose span isn't known, with no limit, or a past cycle has none. Settings › *Menu bar pace* (`settings.TrayPace`, off by default, hidden on Windows, whose tray shows no text but the first card's figure as its icon) puts the same number beside each figure in the menu bar and in its tooltip (`trayPace`, `QuotaWindow.Pace`). See `TestWindowPace`, `TestTrayUsagePace` and `quota-pace.test.cjs`. - Settings › *Menu bar windows* (`settings.TrayWindows`, StrikingRaw on X) picks which of a subscription's windows its menu bar card shows, keyed by provider id (every account of it, the in-use `|*` card too) and by window kind, not position: `trayWindowKind` names a window by its span ("5h", "1d", "7d", "month", "15m"), by `name:` its name when the span isn't known. Unset shows every window, as before; a pick none of whose kinds the card still has shows every window again (`trayShownKinds`), never an empty card. Only the bar's rows, the Linux label and Windows' icon figure are filtered; the tooltip still says every window. One row draws in the menu bar's own font (13pt regular), two stacked rows in 10pt regular, both with digits of one width (`mpRowFont`, `TestTrayRowFont`; qingnianxiaozhe on X found the old 9.5pt semibold and 11pt medium heavier than Surge's and iStat Menus' figures beside them). The GUI learns the kinds from `trayKind` on `/api/usage/quotas` (`withTrayKinds`; model and aside windows get none). The row lists a pill per ticked subscription with two or more kinds, opening the app's menu (All windows, then each kind), shown on Windows too, where the first card's pick decides the tray icon's figure; its code is in `traywindows.js`, imported when Settings draws ticked cards. Per computer through `KeepOwn`. See `TestTrayWindowsPicked`, `TestTrayWindowsKept` and `tray-windows.test.cjs`. - In Usage → Allowances, Trends → Cycle offers each account's own recorded cycle menu beside its curve (`quotaCurve`, `quotaRecordedCycles` in [`app.js`](../../internal/gui/assets/app.js)). The longest window (usually weekly) owns the menu; shorter windows are drawn over the selected dates with their own reset breaks. `/api/usage/quotas/history?days=45` supplies all retained readings, including remote cards. Completed cycles come from observed boundaries, not seven-day arithmetic; an early reset ends the previous cycle at the vendor's new start if it fits between readings, otherwise at the first new reading. Each menu option gives its observed duration, so an early reset is not labelled as a full seven days. The selected meters, plot, legend, tooltip and dashed pace use that cycle's last readings, never today's percentages. A window without a reading in the selected interval says so instead of showing a current value. A local account's past cycle asks `/api/usage/quotas/history/holds?provider=&user=&from=&to=` once per selection (`quotaCycleHoldsOf`), which asks no vendor (#2009, NorethSea): `HistoricalWindowHolds` in [`window_holds_history.go`](../../internal/usage/window_holds_history.go) reckons each window's whole at its own last reading in that cycle, from the request log up to that reading, so the 5-hour figure is the cycle's last 5-hour window, never its short windows added up. Its tooltip names that window's start and the reading's time. It shows "Loading…" until the answer comes. A window it can't reckon says "not enough data" with the reason, as a current card does; a reply that comes after another cycle was picked is dropped, and a card's Refresh or an asked read reckons again. Historical meters show the cycle end and sampling time; current account actions, balances and policies are left out until returning to the current view. Accounts are independent, and a selection survives card refreshes in the same page. Trends → 2 days temporarily shows recent readings; Off removes the curves; the tray always shows its current cycle. See `quota-curve.test.cjs` and the [history limits and reset inference](providers-accounts.md#constraints-and-failure-behavior). diff --git a/internal/gui/api.go b/internal/gui/api.go index 2f706b834..578f65b78 100644 --- a/internal/gui/api.go +++ b/internal/gui/api.go @@ -1379,11 +1379,12 @@ func Handler(w Windows, gw *gateway.Server) http.Handler { // the cards the menu bar shows, any of them (TrayUsage is only the first), // how often, with their logos or not, beside the bird or not, as // Windows' icon or not, and - // with their Pace numbers or not, with magpie's totals' cost or not, and - // which of each subscription's windows + // with their Pace numbers or not, with magpie's totals' cost or not, + // which of each subscription's windows, and the language the tooltip + // is in (yi_time) if (!slices.Equal(settings.Load().TrayUsages, cur.TrayUsages) || in.TrayUsageEvery != cur.TrayUsageEvery || in.TrayNoLogos != cur.TrayNoLogos || in.TrayNoBird != cur.TrayNoBird || in.TrayNoNumber != cur.TrayNoNumber || in.TrayPace != cur.TrayPace || - in.TrayNoCost != cur.TrayNoCost || !maps.EqualFunc(in.TrayWindows, cur.TrayWindows, slices.Equal)) && onTrayUsage != nil { + in.TrayNoCost != cur.TrayNoCost || !maps.EqualFunc(in.TrayWindows, cur.TrayWindows, slices.Equal) || in.Lang != cur.Lang) && onTrayUsage != nil { onTrayUsage() } // an alert turned on or moved is looked at now, the Mac asked for its diff --git a/internal/gui/trayidle_test.go b/internal/gui/trayidle_test.go index cbc7b231a..ce3dd1545 100644 --- a/internal/gui/trayidle_test.go +++ b/internal/gui/trayidle_test.go @@ -22,12 +22,12 @@ func TestTrayIdleTip(t *testing.T) { "magpie\nToday: 1.0K tokens (950 in · 50 out)\n1 request"}, {usage.Totals{}, "magpie\nToday: no requests yet"}, } { - if got := trayIdleTip(c.t, "usd", 0); got != c.want { + if got := trayIdleTip("en", c.t, "usd", 0); got != c.want { t.Errorf("trayIdleTip(%+v) =\n%q, want\n%q", c.t, got, c.want) } } // waybar reads the title as Pango markup: still safe after sniTip - if got := sniTip(trayIdleTip(usage.Totals{Calls: 3, Input: 10, Cost: 2}, "usd", 0)); got != "magpie\nToday: 10 tokens (10 in · 0 out)\n≈$2.00 · 3 requests" { + if got := sniTip(trayIdleTip("en", usage.Totals{Calls: 3, Input: 10, Cost: 2}, "usd", 0)); got != "magpie\nToday: 10 tokens (10 in · 0 out)\n≈$2.00 · 3 requests" { t.Errorf("sniTip: %q", got) } } diff --git a/internal/gui/traymenu.go b/internal/gui/traymenu.go index 24d0b9a30..8746d2d60 100644 --- a/internal/gui/traymenu.go +++ b/internal/gui/traymenu.go @@ -8,7 +8,8 @@ import ( ) // trayZh is the tray menu in Chinese; the page has its own words -// (i18n.js), and these few are all the menu shows (#301). +// (i18n.js), and these few are all the menu and the icon's tooltip show +// (#301). var trayZh = map[string]string{ "Open magpie": "打开 magpie", "Version %s": "版本 %s", @@ -17,6 +18,27 @@ var trayZh = map[string]string{ "Quit magpie": "退出 magpie", "Restart Now to Update": "立即重启以更新", "Restart Now to Update (%d in flight)": "立即重启以更新(%d 个进行中)", + // the tray icon's tooltip (trayusage.go; yi_time on Discord) + "%s used": "已用 %s", + "%s left": "剩余 %s", + "pace %s": "增速 %s", + "resets in %s": "%s 后重置", + "%dd %dh": "%d 天 %d 小时", + "%dh %dm": "%d 小时 %d 分", + "%dm": "%d 分钟", + "as of %s, couldn't be read just now": "截至 %s,暂时无法获取最新额度", + "Jan 2 15:04": "1月2日 15:04", + "Today in magpie": "magpie 今日", + "Last 7 days in magpie": "magpie 近 7 天", + "%d requests": "%d 个请求", + "%d request": "%d 个请求", + ", %d with no known price": ",其中 %d 个没有已知价格", + "%s in": "输入 %s", + "%s out": "输出 %s", + "%s cached": "缓存 %s", + "%s tokens (%s)": "%s token(%s)", + "Today: no requests yet": "今天:还没有请求", + "Today: %s": "今天:%s", } // trayZhTW is the tray menu in Traditional Chinese, with Taiwan's words. @@ -28,6 +50,27 @@ var trayZhTW = map[string]string{ "Quit magpie": "結束 magpie", "Restart Now to Update": "立即重新啟動以更新", "Restart Now to Update (%d in flight)": "立即重新啟動以更新(%d 個進行中)", + // the tray icon's tooltip (trayusage.go; yi_time on Discord) + "%s used": "已用 %s", + "%s left": "剩餘 %s", + "pace %s": "增速 %s", + "resets in %s": "%s 後重設", + "%dd %dh": "%d 天 %d 小時", + "%dh %dm": "%d 小時 %d 分", + "%dm": "%d 分鐘", + "as of %s, couldn't be read just now": "截至 %s,暫時無法取得最新額度", + "Jan 2 15:04": "1月2日 15:04", + "Today in magpie": "magpie 今日", + "Last 7 days in magpie": "magpie 近 7 天", + "%d requests": "%d 個請求", + "%d request": "%d 個請求", + ", %d with no known price": ",其中 %d 個沒有已知價格", + "%s in": "輸入 %s", + "%s out": "輸出 %s", + "%s cached": "快取 %s", + "%s tokens (%s)": "%s token(%s)", + "Today: no requests yet": "今天:還沒有請求", + "Today: %s": "今天:%s", } // trayJa is the tray menu in Japanese. @@ -39,6 +82,27 @@ var trayJa = map[string]string{ "Quit magpie": "magpie を終了", "Restart Now to Update": "今すぐ再起動してアップデート", "Restart Now to Update (%d in flight)": "今すぐ再起動してアップデート(%d 件処理中)", + // the tray icon's tooltip (trayusage.go; yi_time on Discord) + "%s used": "使用済み %s", + "%s left": "残り %s", + "pace %s": "増え方 %s", + "resets in %s": "%s 後にリセット", + "%dd %dh": "%d日 %d時間", + "%dh %dm": "%d時間 %d分", + "%dm": "%d分", + "as of %s, couldn't be read just now": "%s 時点、現在は読み取れません", + "Jan 2 15:04": "1月2日 15:04", + "Today in magpie": "magpie の今日", + "Last 7 days in magpie": "magpie の過去 7 日間", + "%d requests": "%d 件のリクエスト", + "%d request": "%d 件のリクエスト", + ", %d with no known price": "、うち %d 件は価格不明", + "%s in": "入力 %s", + "%s out": "出力 %s", + "%s cached": "キャッシュ %s", + "%s tokens (%s)": "%s トークン(%s)", + "Today: no requests yet": "今日:まだリクエストはありません", + "Today: %s": "今日:%s", } // trayDe is the tray menu in German. @@ -50,9 +114,31 @@ var trayDe = map[string]string{ "Quit magpie": "magpie beenden", "Restart Now to Update": "Jetzt neu starten und aktualisieren", "Restart Now to Update (%d in flight)": "Jetzt neu starten und aktualisieren (%d laufend)", + // the tray icon's tooltip (trayusage.go; yi_time on Discord) + "%s used": "%s verbraucht", + "%s left": "%s übrig", + "pace %s": "Tempo %s", + "resets in %s": "Reset in %s", + "%dd %dh": "%d T %d h", + "%dh %dm": "%d h %d min", + "%dm": "%d min", + "as of %s, couldn't be read just now": "Stand %s, konnte gerade nicht gelesen werden", + "Jan 2 15:04": "2.1. 15:04", + "Today in magpie": "Heute in magpie", + "Last 7 days in magpie": "Letzte 7 Tage in magpie", + "%d requests": "%d Anfragen", + "%d request": "%d Anfrage", + ", %d with no known price": ", %d ohne bekannten Preis", + "%s in": "%s Eingabe", + "%s out": "%s Ausgabe", + "%s cached": "%s Cache", + "%s tokens (%s)": "%s Token (%s)", + "Today: no requests yet": "Heute: noch keine Anfragen", + "Today: %s": "Heute: %s", } -// trayWords are the tray menu's translations by language. +// trayWords are the tray menu's and the tray icon's tooltip's +// translations by language. var trayWords = map[string]map[string]string{"zh": trayZh, "zh-TW": trayZhTW, "ja": trayJa, "de": trayDe} // onLang relabels the tray menu when the Settings page changes the diff --git a/internal/gui/traynumber_test.go b/internal/gui/traynumber_test.go index ee07f7dbd..9c2c4d422 100644 --- a/internal/gui/traynumber_test.go +++ b/internal/gui/traynumber_test.go @@ -19,7 +19,7 @@ func TestTrayIconFigure(t *testing.T) { now := time.Date(2026, 9, 30, 12, 0, 0, 0, time.UTC) cards := trayCards() view := func(ids []string, left bool, pick map[string][]string) []trayCell { - cells, _, _ := trayCardsView(trayPick(cards, ids, now), now, left, false, pick) + cells, _, _ := trayCardsView("en", trayPick(cards, ids, now), now, left, false, pick) return cells } for _, tc := range []struct { diff --git a/internal/gui/traytip_lang_test.go b/internal/gui/traytip_lang_test.go new file mode 100644 index 000000000..deb0d9f9b --- /dev/null +++ b/internal/gui/traytip_lang_test.go @@ -0,0 +1,77 @@ +package gui + +import ( + "strings" + "testing" + "time" + + "github.com/yetone/magpie/internal/provider" + "github.com/yetone/magpie/internal/usage" +) + +// yi_time on Discord: magpie set to Chinese on Windows, and the tray icon's +// tooltip said "Today: 121K tokens (2.9K in · 180 out · 118K cached)" and +// "3 requests" in English. The tooltip is in magpie's language, as the +// tray menu is: the idle tip, magpie's totals and a subscription's +// windows, in every language magpie has. A window's name and the numbers +// are the card's own. +func TestTrayTooltipFollowsMagpiesLanguage(t *testing.T) { + // yi_time's numbers + today := usage.Totals{Calls: 3, Input: 2_900, Output: 180, CacheRead: 118_000} + if got, want := trayIdleTip("zh", today, "usd", 0), "magpie\n今天:121K token(输入 2.9K · 输出 180 · 缓存 118K)\n3 个请求"; got != want { + t.Errorf("zh idle tip =\n%q, want\n%q", got, want) + } + if got, want := trayIdleTip("en", today, "usd", 0), "magpie\nToday: 121K tokens (2.9K in · 180 out · 118K cached)\n3 requests"; got != want { + t.Errorf("en idle tip =\n%q, want\n%q", got, want) + } + if got, want := trayTotalCard("zh", "usage:today", today, "usd", 0).Name, "magpie 今日\n121K token(输入 2.9K · 输出 180 · 缓存 118K)\n3 个请求"; got != want { + t.Errorf("zh total card =\n%q, want\n%q", got, want) + } + + now := time.Now() + asOf := now.Add(-time.Hour) + card := provider.SubscriptionQuota{Provider: "claude", Name: "Claude", AsOf: &asOf, + Windows: []provider.QuotaWindow{{Name: "5h", Used: 42, ResetSecs: 3*3600 + 10*60}}} + _, tip := trayCardText("zh", card, now, false, false, nil) + for _, w := range []string{"Claude\n", "5h 已用 42%", "3 小时 10 分 后重置", "截至 ", "暂时无法获取最新额度"} { + if !strings.Contains(tip, w) { + t.Errorf("zh card tooltip %q lacks %q", tip, w) + } + } + if _, tip := trayCardText("zh", card, now, true, false, nil); !strings.Contains(tip, "5h 剩余 58%") { + t.Errorf("zh card tooltip, what is left: %q", tip) + } + + english := []string{"Today", "tokens", "K in", "0 in", " out", "cached", "request", " used", " left", "resets", "pace ", "as of", "Last 7", "no known price", "couldn't", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} + for _, lang := range []string{"zh", "zh-TW", "ja", "de"} { + priced := today + priced.Cost, priced.Unpriced = 1.5, 1 + readAt := now.Add(-2 * time.Hour) + paced := card + paced.ReadAt = &readAt + paced.Windows = []provider.QuotaWindow{{Name: "5 hours", Used: 42.5, ResetSecs: 3*3600 + 10*60}, {Name: "7 days", Used: 3, ResetSecs: 4*86400 + 3600}, {Name: "x", Used: 1, ResetSecs: 120}} + tips := []string{ + trayIdleTip(lang, priced, "usd", 0), + trayIdleTip(lang, usage.Totals{Calls: 1, Input: 5}, "usd", 0), + trayIdleTip(lang, usage.Totals{}, "usd", 0), + trayTotalCard(lang, "usage:today", priced, "usd", 0).Name, + trayTotalCard(lang, "usage:7d", priced, "usd", 0).Name, + } + for _, left := range []bool{false, true} { + _, tip := trayCardText(lang, paced, now, left, true, nil) + if pace := trayText(lang, "pace %s", ""); !strings.Contains(tip, pace) { + t.Errorf("%s: no %q in %q", lang, pace, tip) + } + tips = append(tips, tip) + } + _, _, view := trayCardsView(lang, []provider.SubscriptionQuota{trayTotalCard(lang, "usage:today", priced, "usd", 0), paced}, now, false, true, nil) + tips = append(tips, view) + for _, tip := range tips { + for _, w := range english { + if strings.Contains(tip, w) { + t.Errorf("%s tooltip says %q in English:\n%s", lang, w, tip) + } + } + } + } +} diff --git a/internal/gui/trayusage.go b/internal/gui/trayusage.go index 82568e394..b92c95b36 100644 --- a/internal/gui/trayusage.go +++ b/internal/gui/trayusage.go @@ -251,9 +251,9 @@ func withTrayKinds(qs []provider.SubscriptionQuota) []provider.SubscriptionQuota return out } -// trayUsageText is trayCardText with every window shown. +// trayUsageText is trayCardText with every window shown, in English. func trayUsageText(q provider.SubscriptionQuota, now time.Time, left, pace bool) (label, tip string) { - return trayCardText(q, now, left, pace, nil) + return trayCardText("en", q, now, left, pace, nil) } // trayCardText is the menu bar's text for a card and the tooltip that @@ -261,8 +261,9 @@ func trayUsageText(q provider.SubscriptionQuota, now time.Time, left, pace bool) // it starts again. With pace (settings.TrayPace) each window's Pace number // follows its figure, in both, as the Usage page's cards show it. The text // has the windows of the kinds given alone (trayShownKinds); the tooltip -// has them all. -func trayCardText(q provider.SubscriptionQuota, now time.Time, left, pace bool, kinds []string) (label, tip string) { +// has them all. The tooltip's own words are in lang (trayLang), as the +// tray menu's are; a window's name and an error are the card's. +func trayCardText(lang string, q provider.SubscriptionQuota, now time.Time, left, pace bool, kinds []string) (label, tip string) { if strings.HasPrefix(q.Provider, trayTotal) { return q.Balance, q.Name // trayTotalCard's: its rows, and its tooltip } @@ -275,7 +276,7 @@ func trayCardText(q provider.SubscriptionQuota, now time.Time, left, pace bool, if q.Balance == "" { return "", "" } - return q.Balance, q.Name + " · " + q.Balance + trayAsOf(q) + return q.Balance, q.Name + " · " + q.Balance + trayAsOf(lang, q) } readAt := now if q.ReadAt != nil && !q.ReadAt.After(now) { @@ -291,16 +292,16 @@ func trayCardText(q provider.SubscriptionQuota, now time.Time, left, pace bool, } used := math.Max(0, math.Min(100, w.Used)) n := int(math.Round(used)) - word := "used" + word := "%s used" if left { used = 100 - used - n, word = 100-n, "left" + n, word = 100-n, "%s left" } pct := fmt.Sprintf("%d%%", n) row, paceNote := pct, "" if p, ok := w.Pace(readAt, now); pace && ok { row = pct + " " + trayPace(p, left) - paceNote = " · pace " + trayPace(p, left) + paceNote = " · " + trayText(lang, "pace %s", trayPace(p, left)) } if kinds == nil || picked { short = append(short, row) @@ -309,20 +310,20 @@ func trayCardText(q provider.SubscriptionQuota, now time.Time, left, pace bool, if used != math.Trunc(used) { tipPct = fmt.Sprintf("%.1f%%", used) } - line := w.Name + " " + tipPct + " " + word + line := w.Name + " " + trayText(lang, word, tipPct) if c := w.Count(left); c != "" { - line = w.Name + " " + c + " · " + tipPct + " " + word + line = w.Name + " " + c + " · " + trayText(lang, word, tipPct) } line += paceNote if at := resetAt(w, now); !at.IsZero() && at.After(now) { - line += " · resets in " + until(at.Sub(now)) + line += " · " + trayText(lang, "resets in %s", until(lang, at.Sub(now))) } long = append(long, line) } if len(short) > 2 { short = short[:2] } - return strings.Join(short, " · "), q.Name + "\n" + strings.Join(long, "\n") + trayAsOf(q) + return strings.Join(short, " · "), q.Name + "\n" + strings.Join(long, "\n") + trayAsOf(lang, q) } // trayPace is a window's Pace number as the Usage page writes it @@ -347,11 +348,11 @@ func trayPace(p float64, left bool) string { // trayAsOf is the tooltip's word that a card stands in for one that // couldn't be read just now, and when it was read (the Usage page's // "As of …"); nothing for a reading just made. -func trayAsOf(q provider.SubscriptionQuota) string { +func trayAsOf(lang string, q provider.SubscriptionQuota) string { if q.AsOf == nil { return "" } - return "\nas of " + q.AsOf.Local().Format("Jan 2 15:04") + ", couldn't be read just now" + return "\n" + trayText(lang, "as of %s, couldn't be read just now", q.AsOf.Local().Format(trayText(lang, "Jan 2 15:04"))) } func resetAt(w provider.QuotaWindow, now time.Time) time.Time { @@ -364,24 +365,24 @@ func resetAt(w provider.QuotaWindow, now time.Time) time.Time { return time.Time{} } -// until says a wait in the largest two units: 3d 4h, 2h 10m, 7m. -func until(d time.Duration) string { +// until says a wait in the largest two units, in lang: 3d 4h, 2h 10m, 7m. +func until(lang string, d time.Duration) string { d = d.Round(time.Minute) days, hours, mins := int(d/(24*time.Hour)), int(d%(24*time.Hour)/time.Hour), int(d%time.Hour/time.Minute) switch { case days > 0: - return fmt.Sprintf("%dd %dh", days, hours) + return trayText(lang, "%dd %dh", days, hours) case hours > 0: - return fmt.Sprintf("%dh %dm", hours, mins) + return trayText(lang, "%dh %dm", hours, mins) } - return fmt.Sprintf("%dm", max(mins, 1)) + return trayText(lang, "%dm", max(mins, 1)) } // trayUsageCards are the cards settings.TrayUsages names, in its order, // among the Usage page's (cached as there), and magpie's own totals it // names (trayTotal); one gone is left out. The vendors aren't asked when // only totals are named. -func trayUsageCards(ctx context.Context, ids []string) []provider.SubscriptionQuota { +func trayUsageCards(ctx context.Context, lang string, ids []string) []provider.SubscriptionQuota { if len(ids) == 0 { return nil } @@ -401,7 +402,7 @@ func trayUsageCards(ctx context.Context, ids []string) []provider.SubscriptionQu currency, rate = trayCurrency() noCost = settings.Load().TrayNoCost } - cards = append(cards, trayTotalCard(id, trayMoney(trayTotalSum(p), noCost), currency, rate)) + cards = append(cards, trayTotalCard(lang, id, trayMoney(trayTotalSum(p), noCost), currency, rate)) } return trayPick(cards, ids, time.Now()) } @@ -480,14 +481,14 @@ var trayQuerySum = func(p usage.Period) usage.Totals { return usage.QueryPage(p, // marked Σ so it doesn't read as the input alone (NextCommit on Discord), // over the cost, in the currency Settings says, "+" when some calls had no // known price; nothing beneath the tokens when none had one. Its name is -// the tooltip, which spells out the input, output and cache. -func trayTotalCard(id string, t usage.Totals, currency string, rate float64) provider.SubscriptionQuota { - when := "Today" +// the tooltip, which spells out the input, output and cache, in lang. +func trayTotalCard(lang, id string, t usage.Totals, currency string, rate float64) provider.SubscriptionQuota { + when := "Today in magpie" if p, _ := trayTotalPeriod(id); p == usage.Week { - when = "Last 7 days" + when = "Last 7 days in magpie" } rows := []string{"Σ" + trayCount(t.Tokens()+t.CacheRead+t.CacheWrite)} - tip := when + " in magpie\n" + trayTokens(t) + tip := trayText(lang, when) + "\n" + trayTokens(lang, t) if t.Cost > 0 { c := usage.FormatCost(t.Cost, currency, rate) if t.Unpriced > 0 { @@ -496,9 +497,9 @@ func trayTotalCard(id string, t usage.Totals, currency string, rate float64) pro rows = append(rows, c) tip += "\n≈" + c } - tip += fmt.Sprintf("\n%d requests", t.Calls) + tip += "\n" + trayText(lang, "%d requests", t.Calls) if t.Unpriced > 0 { - tip += fmt.Sprintf(", %d with no known price", t.Unpriced) + tip += trayText(lang, ", %d with no known price", t.Unpriced) } return provider.SubscriptionQuota{Provider: id, Name: tip, Balance: strings.Join(rows, " · ")} } @@ -524,13 +525,13 @@ func trayCurrency() (currency string, rate float64) { } // trayTokens is a total's every token, the cache's too, with what they -// were: "6.3M tokens (912K in · 318K out · 5.1M cached)". -func trayTokens(t usage.Totals) string { - s := trayCount(t.Tokens()+t.CacheRead+t.CacheWrite) + " tokens (" + trayCount(t.Input) + " in · " + trayCount(t.Output) + " out" +// were, in lang: "6.3M tokens (912K in · 318K out · 5.1M cached)". +func trayTokens(lang string, t usage.Totals) string { + parts := []string{trayText(lang, "%s in", trayCount(t.Input)), trayText(lang, "%s out", trayCount(t.Output))} if cached := t.CacheRead + t.CacheWrite; cached > 0 { - s += " · " + trayCount(cached) + " cached" + parts = append(parts, trayText(lang, "%s cached", trayCount(cached))) } - return s + ")" + return trayText(lang, "%s tokens (%s)", trayCount(t.Tokens()+t.CacheRead+t.CacheWrite), strings.Join(parts, " · ")) } // trayIdleTip is the tooltip while the menu bar shows no cards: magpie's @@ -538,11 +539,13 @@ func trayTokens(t usage.Totals) string { // (ylorn on Discord: a Linux bar's tooltip said only "magpie"): every // token, split into input, output and cache as the usage:today card's // tooltip does (NextCommit on Discord), then the cost and the requests. -func trayIdleTip(t usage.Totals, currency string, rate float64) string { +// It is in lang, magpie's language as the tray menu's is (yi_time on +// Discord: in English on a Windows magpie set to Chinese). +func trayIdleTip(lang string, t usage.Totals, currency string, rate float64) string { if t.Calls == 0 { - return "magpie\nToday: no requests yet" + return "magpie\n" + trayText(lang, "Today: no requests yet") } - line := "Today: " + trayTokens(t) + "\n" + line := trayText(lang, "Today: %s", trayTokens(lang, t)) + "\n" if t.Cost > 0 { c := usage.FormatCost(t.Cost, currency, rate) if t.Unpriced > 0 { @@ -550,11 +553,11 @@ func trayIdleTip(t usage.Totals, currency string, rate float64) string { } line += "≈" + c + " · " } - n := "requests" + n := "%d requests" if t.Calls == 1 { - n = "request" + n = "%d request" } - return fmt.Sprintf("magpie\n%s%d %s", line, t.Calls, n) + return "magpie\n" + line + trayText(lang, n, t.Calls) } // trayCount is a count as the Usage page says it in English: 133M, 1.2M, @@ -685,9 +688,9 @@ func trayPlain(cells []trayCell) []trayCell { return out } -// trayUsageView is trayCardsView with every window shown. +// trayUsageView is trayCardsView with every window shown, in English. func trayUsageView(cards []provider.SubscriptionQuota, now time.Time, left, pace bool) (cells []trayCell, label, tip string) { - return trayCardsView(cards, now, left, pace, nil) + return trayCardsView("en", cards, now, left, pace, nil) } // trayCardsView is what the tray shows for the cards: a cell for each @@ -695,10 +698,10 @@ func trayUsageView(cards []provider.SubscriptionQuota, now time.Time, left, pace // " | " for a tray that shows text; and a tooltip spelling each out. A // card's rows are the windows its provider's kinds in pick name // (settings.TrayWindows), all when it names none. -func trayCardsView(cards []provider.SubscriptionQuota, now time.Time, left, pace bool, pick map[string][]string) (cells []trayCell, label, tip string) { +func trayCardsView(lang string, cards []provider.SubscriptionQuota, now time.Time, left, pace bool, pick map[string][]string) (cells []trayCell, label, tip string) { var labels, tips []string for _, q := range cards { - l, t := trayCardText(q, now, left, pace, pick[q.Provider]) + l, t := trayCardText(lang, q, now, left, pace, pick[q.Provider]) if t != "" { tips = append(tips, t) } diff --git a/internal/gui/trayusage_nocost_test.go b/internal/gui/trayusage_nocost_test.go index de6a6069a..18bf50720 100644 --- a/internal/gui/trayusage_nocost_test.go +++ b/internal/gui/trayusage_nocost_test.go @@ -28,7 +28,7 @@ func TestTrayNoCost(t *testing.T) { if err := settings.Save(settings.Settings{TrayUsages: ids}); err != nil { t.Fatal(err) } - _, label, _ := trayUsageView(trayUsageCards(context.Background(), ids), time.Now(), false, false) + _, label, _ := trayUsageView(trayUsageCards(context.Background(), "en", ids), time.Now(), false, false) if label != "Σ47M · $128 | Σ6.3M · $3.40+" { t.Errorf("cost on: label %q", label) } @@ -36,7 +36,7 @@ func TestTrayNoCost(t *testing.T) { if err := settings.Save(settings.Settings{TrayUsages: ids, TrayNoCost: true}); err != nil { t.Fatal(err) } - cells, label, tip := trayUsageView(trayUsageCards(context.Background(), ids), time.Now(), false, false) + cells, label, tip := trayUsageView(trayUsageCards(context.Background(), "en", ids), time.Now(), false, false) if label != "Σ47M | Σ6.3M" { t.Errorf("cost off: label %q, want the tokens alone", label) } @@ -50,10 +50,10 @@ func TestTrayNoCost(t *testing.T) { t.Errorf("cost off: tooltip %q\nwant %q", tip, want) } // the tooltip with no cards, as the watch loop makes it - if got := trayIdleTip(trayMoney(sums[usage.Today], true), "usd", 0); got != "magpie\nToday: 6.3M tokens (912K in · 318K out · 5.1M cached)\n152 requests" { + if got := trayIdleTip("en", trayMoney(sums[usage.Today], true), "usd", 0); got != "magpie\nToday: 6.3M tokens (912K in · 318K out · 5.1M cached)\n152 requests" { t.Errorf("cost off: idle tooltip %q", got) } - if got := trayIdleTip(trayMoney(sums[usage.Today], false), "usd", 0); !strings.Contains(got, "≈$3.40+") { + if got := trayIdleTip("en", trayMoney(sums[usage.Today], false), "usd", 0); !strings.Contains(got, "≈$3.40+") { t.Errorf("cost on: idle tooltip %q", got) } } diff --git a/internal/gui/trayusage_pick_test.go b/internal/gui/trayusage_pick_test.go index 5ed70648d..ca29094d2 100644 --- a/internal/gui/trayusage_pick_test.go +++ b/internal/gui/trayusage_pick_test.go @@ -28,7 +28,7 @@ func TestTrayWindowsPicked(t *testing.T) { }} cards := []provider.SubscriptionQuota{claude, codex} rows := func(pick map[string][]string) ([][]string, string) { - cells, _, tip := trayCardsView(cards, now, false, false, pick) + cells, _, tip := trayCardsView("en", cards, now, false, false, pick) var out [][]string for _, c := range cells { out = append(out, c.Rows) @@ -57,7 +57,7 @@ func TestTrayWindowsPicked(t *testing.T) { t.Fatalf("gone: %q", got) } // the Linux tray's text follows it too - if _, label, _ := trayCardsView(cards, now, true, false, map[string][]string{"claude": {"5h"}}); label != "58% | 90% · 80%" { + if _, label, _ := trayCardsView("en", cards, now, true, false, map[string][]string{"claude": {"5h"}}); label != "58% | 90% · 80%" { t.Fatalf("text: %q", label) } } @@ -134,7 +134,7 @@ func TestTrayWindowsPickAside(t *testing.T) { t.Fatalf("kinds: %+v", out) } rows := func(pick []string) []string { - cells, _, _ := trayCardsView([]provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": pick}) + cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": pick}) return cells[0].Rows } if got := rows(nil); !slices.Equal(got, []string{"30%"}) { @@ -149,7 +149,7 @@ func TestTrayWindowsPickAside(t *testing.T) { if got := rows([]string{"7d", "7d:grok bot"}); !slices.Equal(got, []string{"30%", "64%"}) { t.Fatalf("both: %q", got) } - _, _, tip := trayCardsView([]provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": {"7d:grok bot"}}) + _, _, tip := trayCardsView("en", []provider.SubscriptionQuota{cursor}, now, false, false, map[string][]string{"cursor": {"7d:grok bot"}}) if !strings.Contains(tip, "Grok Bot 64%") { t.Fatalf("tooltip: %q", tip) } @@ -162,7 +162,7 @@ func TestTrayWindowsPickAside(t *testing.T) { if ws := withTrayKinds([]provider.SubscriptionQuota{two})[0].Windows; ws[0].TrayKind != "7d:requests" || ws[1].TrayKind != "7d:tokens" { t.Fatalf("one span twice: %+v", ws) } - cells, _, _ := trayCardsView([]provider.SubscriptionQuota{two}, now, false, false, map[string][]string{"x": {"7d:tokens"}}) + cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{two}, now, false, false, map[string][]string{"x": {"7d:tokens"}}) if !slices.Equal(cells[0].Rows, []string{"20%"}) { t.Fatalf("Tokens alone: %q", cells[0].Rows) } diff --git a/internal/gui/trayusage_shared_test.go b/internal/gui/trayusage_shared_test.go index ceeec7d92..a3e9e5e2f 100644 --- a/internal/gui/trayusage_shared_test.go +++ b/internal/gui/trayusage_shared_test.go @@ -46,7 +46,7 @@ func antigravityStarter() provider.SubscriptionQuota { func TestTrayAntigravityPools(t *testing.T) { now := time.Date(2026, 10, 31, 3, 0, 0, 0, time.UTC) q := antigravityStarter() - cells, label, tip := trayCardsView([]provider.SubscriptionQuota{q}, now, true, false, nil) + cells, label, tip := trayCardsView("en", []provider.SubscriptionQuota{q}, now, true, false, nil) if len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"94%", "0%"}) || cells[0].ID != "antigravity|someone@gmail.com" { t.Fatalf("cells %+v", cells) } @@ -76,7 +76,7 @@ func TestTrayAntigravityPools(t *testing.T) { t.Fatalf("kinds %q", kinds) } // the Gemini pool alone - if cells, _, _ := trayCardsView([]provider.SubscriptionQuota{q}, now, true, false, map[string][]string{"antigravity": {"7d:gemini · 7 days"}}); !slices.Equal(cells[0].Rows, []string{"94%"}) { + if cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{q}, now, true, false, map[string][]string{"antigravity": {"7d:gemini · 7 days"}}); !slices.Equal(cells[0].Rows, []string{"94%"}) { t.Fatalf("the Gemini pool alone: %q", cells[0].Rows) } if q.Windows[6].Name != "7 days" || q.Windows[6].TrayKind != "" { @@ -92,7 +92,7 @@ func TestTrayModelWindows(t *testing.T) { q := antigravityStarter() q.Windows = slices.DeleteFunc(q.Windows, func(w provider.QuotaWindow) bool { return w.Pool != "" }) q.Windows[3].Used = 40 // Gemini 3 Flash, the family's tightest - cells, _, tip := trayCardsView([]provider.SubscriptionQuota{q}, now, false, false, nil) + cells, _, tip := trayCardsView("en", []provider.SubscriptionQuota{q}, now, false, false, nil) if len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"100%", "100%"}) { t.Fatalf("cells %+v", cells) } @@ -115,7 +115,7 @@ func TestTrayModelWindows(t *testing.T) { {Name: "gemini-2.5-pro", Model: "gemini-2.5-pro", Used: 12}, {Name: "gemini-2.5-flash", Model: "gemini-2.5-flash", Used: 30}, }} - if cells, _, _ := trayCardsView([]provider.SubscriptionQuota{gemini}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"30%", "12%"}) { + if cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{gemini}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"30%", "12%"}) { t.Fatalf("gemini %+v", cells) } } @@ -129,14 +129,14 @@ func TestTraySetAsideWindows(t *testing.T) { {Name: "Weekly", Used: 30, Span: 7 * 24 * time.Hour, Aside: true}, {Name: "Session limit", Used: 10, Aside: true}, }} - if cells, _, _ := trayCardsView([]provider.SubscriptionQuota{ollama}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"30%", "10%"}) { + if cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{ollama}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"30%", "10%"}) { t.Fatalf("ollama %+v", cells) } text := provider.SubscriptionQuota{Provider: "autoclaw", Name: "AutoClaw", Windows: []provider.QuotaWindow{ {Name: "积分余额", Display: "120", Text: true, Aside: true}, {Name: "Extra usage", Display: "$3.00", Aside: true}, }} - if cells, _, tip := trayCardsView([]provider.SubscriptionQuota{text}, now, false, false, nil); len(cells) != 0 || tip != "" { + if cells, _, tip := trayCardsView("en", []provider.SubscriptionQuota{text}, now, false, false, nil); len(cells) != 0 || tip != "" { t.Fatalf("text rows made a cell: %+v %q", cells, tip) } claude := provider.SubscriptionQuota{Provider: "claude", Name: "Claude", Windows: []provider.QuotaWindow{ @@ -144,7 +144,7 @@ func TestTraySetAsideWindows(t *testing.T) { {Name: "Extra", Used: 90, Span: 30 * 24 * time.Hour, Aside: true}, {Name: "Opus", Used: 80, Span: 7 * 24 * time.Hour, Model: "opus"}, }} - if cells, _, _ := trayCardsView([]provider.SubscriptionQuota{claude}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"42%"}) { + if cells, _, _ := trayCardsView("en", []provider.SubscriptionQuota{claude}, now, false, false, nil); len(cells) != 1 || !slices.Equal(cells[0].Rows, []string{"42%"}) { t.Fatalf("claude %+v", cells) } } diff --git a/internal/gui/trayusage_total_test.go b/internal/gui/trayusage_total_test.go index 445de65ee..8803de558 100644 --- a/internal/gui/trayusage_total_test.go +++ b/internal/gui/trayusage_total_test.go @@ -26,7 +26,7 @@ func TestTrayTotals(t *testing.T) { // a period the Usage page has no window for, or no total at all, is // left out, as a card no longer there is - cards := trayUsageCards(context.Background(), []string{"usage:7d", "usage:3d", "usage:", "usage:today"}) + cards := trayUsageCards(context.Background(), "en", []string{"usage:7d", "usage:3d", "usage:", "usage:today"}) if !slices.Equal(asked, []usage.Period{usage.Week, usage.Today}) { t.Fatalf("summed %v, want 7d then today", asked) } @@ -57,14 +57,14 @@ func TestTrayTotals(t *testing.T) { // nothing priced: the tokens alone; nothing at all: still a 0, so the // menu bar doesn't look broken first thing in the morning - if q := trayTotalCard("usage:today", usage.Totals{Calls: 3, Input: 950, Unpriced: 3}, "usd", 0); q.Balance != "Σ950" { + if q := trayTotalCard("en", "usage:today", usage.Totals{Calls: 3, Input: 950, Unpriced: 3}, "usd", 0); q.Balance != "Σ950" { t.Errorf("unpriced: %q", q.Balance) } - if q := trayTotalCard("usage:today", usage.Totals{}, "usd", 0); q.Balance != "Σ0" { + if q := trayTotalCard("en", "usage:today", usage.Totals{}, "usd", 0); q.Balance != "Σ0" { t.Errorf("none: %q", q.Balance) } // in the currency Settings says - if q := trayTotalCard("usage:today", usage.Totals{Input: 1000, Cost: 2}, "cny", 7.1); q.Balance != "Σ1.0K · ¥14.20" { + if q := trayTotalCard("en", "usage:today", usage.Totals{Input: 1000, Cost: 2}, "cny", 7.1); q.Balance != "Σ1.0K · ¥14.20" { t.Errorf("cny: %q", q.Balance) } @@ -86,7 +86,7 @@ func TestTrayTotalsBesideCards(t *testing.T) { old := trayTotalSum trayTotalSum = func(usage.Period) usage.Totals { return usage.Totals{Input: 5000, Output: 1000, Cost: 0.12} } t.Cleanup(func() { trayTotalSum = old }) - cards := append(trayCards(), trayTotalCard("usage:today", trayTotalSum(usage.Today), "usd", 0)) + cards := append(trayCards(), trayTotalCard("en", "usage:today", trayTotalSum(usage.Today), "usd", 0)) now := time.Date(2026, 9, 30, 12, 0, 0, 0, time.UTC) cells, label, _ := trayUsageView(trayPick(cards, []string{"usage:today", "claude|a@b.c"}, now), now, false, false) if label != "Σ6.0K · $0.120 | 42% · 18%" { @@ -123,7 +123,7 @@ func TestTrayTotalIsTheLedgers(t *testing.T) { if sum != ledgerPage(usage.Today, usage.Filter{}, 0, 1).Totals { t.Fatalf("menu bar %+v, ledger %+v", sum, ledgerPage(usage.Today, usage.Filter{}, 0, 1).Totals) } - if q := trayTotalCard("usage:today", sum, "usd", 0); !strings.HasPrefix(q.Balance, "Σ9.2K") || !strings.Contains(q.Name, "9.2K tokens (1.0K in · 200 out · 8.0K cached)") { + if q := trayTotalCard("en", "usage:today", sum, "usd", 0); !strings.HasPrefix(q.Balance, "Σ9.2K") || !strings.Contains(q.Name, "9.2K tokens (1.0K in · 200 out · 8.0K cached)") { t.Fatalf("%q %q", q.Balance, q.Name) } } diff --git a/internal/gui/trayusage_tray.go b/internal/gui/trayusage_tray.go index 31c40fbca..944ad5a3e 100644 --- a/internal/gui/trayusage_tray.go +++ b/internal/gui/trayusage_tray.go @@ -47,14 +47,16 @@ func (h *host) watchTrayUsage() { for { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) s := settings.Load() - cells, label, tip := trayCardsView(trayUsageCards(ctx, s.TrayUsages), time.Now(), s.QuotaLeft, s.TrayPace, s.TrayWindows) + // in magpie's language, as the tray menu is (yi_time) + lang := trayLang(s.Lang, systemLang) + cells, label, tip := trayCardsView(lang, trayUsageCards(ctx, lang, s.TrayUsages), time.Now(), s.QuotaLeft, s.TrayPace, s.TrayWindows) cancel() if s.TrayNoLogos { cells = trayPlain(cells) } if tip == "" { currency, rate := trayCurrency() - tip = trayIdleTip(trayMoney(trayTotalSum(usage.Today), s.TrayNoCost), currency, rate) + tip = trayIdleTip(lang, trayMoney(trayTotalSum(usage.Today), s.TrayNoCost), currency, rate) } // Windows' tray shows no text: the first card's figure is its // icon instead (traynumber.go), drawn for the taskbar's size and diff --git a/internal/gui/traywindows_darwin_test.go b/internal/gui/traywindows_darwin_test.go index e65e04498..8267b48eb 100644 --- a/internal/gui/traywindows_darwin_test.go +++ b/internal/gui/traywindows_darwin_test.go @@ -20,8 +20,8 @@ func TestTrayImageOneWindow(t *testing.T) { t.Fatal(err) } cards := trayCards()[:2] - both, _, _ := trayCardsView(cards, time.Now(), false, false, nil) - one, _, _ := trayCardsView(cards, time.Now(), false, false, map[string][]string{"claude": {"5h"}}) + both, _, _ := trayCardsView("en", cards, time.Now(), false, false, nil) + one, _, _ := trayCardsView("en", cards, time.Now(), false, false, map[string][]string{"claude": {"5h"}}) if len(both[0].Rows) != 2 || len(one[0].Rows) != 1 || one[0].Rows[0] != "42%" || len(one[1].Rows) != 2 { t.Fatalf("both %q %q, one %q %q", both[0].Rows, both[1].Rows, one[0].Rows, one[1].Rows) }