yi_time on Discord (Windows, v0.1.2777, magpie in Chinese): the tray
icon's tooltip said "WorkBuddy / Credits 0 / 500 credits · 已用 0% · 27 天
13 小时 后重置". The window's name and unit come from the WorkBuddy plugin
in English. The Usage page's card says both with t() (t(w.name),
t(w.unit)), so it read 积分 there, but trayCardText wrote them as given.
The fix is for every window, not WorkBuddy only:
- traywords.go reads the page's own table (embedded assets/i18n.js, once)
and trayCardText says each window's name, and each " · " part of a
pool's or family's name, and its count's unit, from it. The tray now
reads as the card does in zh, zh-TW, ja and de; English is unchanged.
- i18n.js gains the window names and units plugins report that it lacked
in every language, so the card had them in English too: Extra credits,
Prepaid credits, Free model tokens (workbuddy); Add-on, Dedicated,
Shared, Total credits (qoder); Monthly credits, Purchased credits,
5-hour window (agnes); Promotional Credits (gcp-ai); Free models
(devin); Free usage, Monthly, Included (cursor); Free trial (kiro);
Dollar Usage (trae); Neurons/day (free allowance) (cloudflare-workers-ai);
AI Q&A and the unit "questions" (orcaterm). Collected from
magpie-community/plugins origin/main usage() results. No plugin change
is needed: the plugins send English words, and magpie translates them.
Tests:
- TestTrayTooltipSaysWindowWordsAsTheCard: yi_time's card (Credits,
0 / 500 credits, 27d 13h) gives the exact tooltip in all five languages,
and a pool's window ("Gemini · 5 hours") is said in its parts.
- TestPluginWindowWordsSaidInEveryLanguage: each word above is in every
language's table. TestParsePageWords: two pairs to a line, escapes, a
comment and NOTICES left out.
- quota-window-words.test.cjs: the Usage card says WorkBuddy's and
Qoder's window names and unit in en, zh, zh-TW, ja, de, chromium and
webkit, 1100px and 420px.
Run at the pushed head 3886c2cc0's tree (on origin/main 84da86ebd), on mote:
- go test -run 'Tray|PageWords|PluginWindow|Translated|Budget'
./internal/gui: ok. GOOS=linux go vet -tags nogui ./internal/gui,
GOOS=windows go vet ./internal/gui: ok. gofmt -l: clean.
- node --test quota-window-words, i18n-keys, quota-credits,
quota-name-translated: 52 pass, 0 fail.
Before the rebase (on 05aba5ca4): go test ./internal/gui whole: all ok but
TestMainWindowCorners/macOS_26_SDK, which is #3949 (mote's macOS 27). The
GUI files that name any new key (credit-days, fold-show-grip,
plugin-namesake, plugin-option-words, quota-curve, usage-fold,
usage-merge, quota-pools, quota-pool-order, quota-warm, warm-reset-asleep,
warm-at-times, gateway-systemone): 250 pass, 6 fail, all in usage-fold,
en included; usage-fold fails 4 of 10 on an untouched 05aba5ca4 too
(#3415).
Broken by hand: with trayusage.go as it was, the tray test is red with
the reporter's line ("Credits 0 / 500 credits · 已用 0%"); with i18n.js as
it was, the words test and quota-window-words are red in zh, zh-TW, ja, de.
Not tried: the tooltip in a real tray on Windows; the whole GUI suite (no
layout change or API call). A window name a plugin adds later, and the
Chinese names some Chinese plugins send (积分, 限时积分), still read as sent
until i18n.js has them. A balance window's display text ("120 credits")
is the plugin's text and stays as sent, on the card too.
81 lines
4.8 KiB
JavaScript
81 lines
4.8 KiB
JavaScript
// Run with Node's test runner and Playwright on the module path; see README.md.
|
|
// yi_time on Discord: a plugin names and counts its usage windows in
|
|
// English (WorkBuddy's "Credits" and "Extra credits", in "credits"), and
|
|
// the Usage page's card says them in the page's language, in every
|
|
// language magpie has, as the tray's tooltip does (traywords.go). No
|
|
// backend, the API is faked here.
|
|
const assert = require("node:assert/strict");
|
|
const fs = require("node:fs/promises");
|
|
const path = require("node:path");
|
|
const { test } = require("node:test");
|
|
const { chromium, webkit } = require("playwright");
|
|
|
|
const assets = path.resolve(__dirname, "../assets");
|
|
const quotas = [
|
|
{ provider: "workbuddy", name: "WorkBuddy", icon: "workbuddy-color", plan: "Pro", user: "李雷", windows: [
|
|
{ name: "Credits", used: 0, display: "0 / 500", amount: 0, limit: 500, unit: "credits" },
|
|
{ name: "Extra credits", used: 10, display: "20 / 200", amount: 20, limit: 200, unit: "credits", aside: true },
|
|
] },
|
|
{ provider: "qoder", name: "Qoder", icon: "qoder", plan: "Pro", user: "me@example.com", windows: [
|
|
{ name: "Add-on credits", used: 50, display: "50 / 100", amount: 50, limit: 100, unit: "credits" },
|
|
] },
|
|
];
|
|
|
|
function serve(lang) {
|
|
const settings = { lang, theme: "light", currency: "usd" };
|
|
const state = { agents: [], profiles: [], settings };
|
|
return async (r) => {
|
|
const url = new URL(r.request().url());
|
|
const json = (data) => r.fulfill({ json: data });
|
|
if (url.pathname === "/boot.js") return r.fulfill({ contentType: "text/javascript", body: `window.bootPrefs = {lang:"${lang}",theme:"light",web:true};` });
|
|
if (url.pathname === "/wails/runtime.js") return r.fulfill({ contentType: "text/javascript", body: "export const Window = {};" });
|
|
if (url.pathname === "/api/state") return json(state);
|
|
if (url.pathname === "/api/settings") return json(settings);
|
|
if (url.pathname === "/api/providers") return json({ providers: [], presets: [], excluded: [], gateway: { running: true, window: true, url: "http://127.0.0.1:3999" } });
|
|
if (url.pathname === "/api/usage/quotas") return json(quotas);
|
|
if (url.pathname === "/api/plugins") return json({ plugins: [] });
|
|
if (url.pathname.startsWith("/api/")) return json({});
|
|
const file = path.join(assets, url.pathname === "/" ? "index.html" : url.pathname);
|
|
const contentType = { ".html": "text/html", ".js": "text/javascript", ".css": "text/css", ".svg": "image/svg+xml", ".png": "image/png" }[path.extname(file)];
|
|
try { await r.fulfill({ body: await fs.readFile(file), contentType }); } catch { await r.fulfill({ status: 404, body: "" }); }
|
|
};
|
|
}
|
|
|
|
const words = {
|
|
en: { wb: ["Credits", "Extra credits"], unit: "credits", qoder: "Add-on credits" },
|
|
zh: { wb: ["积分", "额外积分"], unit: "积分", qoder: "加购积分" },
|
|
"zh-TW": { wb: ["積分", "額外積分"], unit: "積分", qoder: "加購積分" },
|
|
ja: { wb: ["クレジット", "追加クレジット"], unit: "クレジット", qoder: "アドオンクレジット" },
|
|
de: { wb: ["Credits", "Zusätzliche Credits"], unit: "Credits", qoder: "Add-on-Credits" },
|
|
};
|
|
const squash = (s) => s.replace(/\s+/g, " ").trim();
|
|
|
|
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
|
|
for (const width of [1100, 420]) {
|
|
for (const [lang, w] of Object.entries(words)) {
|
|
test(`${engine} ${width}px ${lang}: a plugin's window names and units in the page's language`, async (t) => {
|
|
const browser = await (engine === "webkit" ? webkit.launch() : chromium.launch({ channel: "chromium" }));
|
|
t.after(() => browser.close());
|
|
const page = await (await browser.newContext({ viewport: { width, height: 800 }, reducedMotion: "reduce" })).newPage();
|
|
page.setDefaultTimeout(5000);
|
|
page.setDefaultNavigationTimeout(60000);
|
|
const errors = [];
|
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
await page.route("**/*", serve(lang));
|
|
await page.goto("http://magpie.test/?view=usage");
|
|
|
|
const card = page.locator(".subscription-card", { hasText: "WorkBuddy" });
|
|
await card.locator(".quota-name").first().waitFor();
|
|
const names = (await card.locator(".quota-name").allTextContents()).map(squash);
|
|
for (const n of w.wb) assert.ok(names.includes(n), `${lang} WorkBuddy names ${JSON.stringify(names)} lack ${n}`);
|
|
const count = squash(await card.locator(".quota-n").first().textContent());
|
|
assert.ok(count.startsWith("0 / 500 " + w.unit), `${lang} count ${count}`);
|
|
const qoder = page.locator(".subscription-card", { hasText: "Qoder" });
|
|
await qoder.locator(".quota-name").first().waitFor();
|
|
assert.equal(squash(await qoder.locator(".quota-name").first().textContent()), w.qoder);
|
|
assert.deepEqual(errors, []);
|
|
});
|
|
}
|
|
}
|
|
}
|