tui: speaks the language picked in Settings, Simplified Chinese first
zaidu259434 on X asked why magpie's CLI/TUI pages don't support Chinese. The GUI had en/zh/zh-TW/ja/de; the TUI had English only. - internal/uilang: the language pick the tray already made (the setting, else the system's: zh-Hant regions to zh-TW, other zh to zh, ja, de) moved out of internal/gui so the TUI asks the same function. The tray calls it unchanged; its tests moved with it. - internal/tui/i18n.go: tr/trf look a string up by its English text in a zh table (464 entries), falling back to the English. zh-TW reads Simplified for now; ja and de stay English. Terms come from the GUI's i18n.js where the same word is there (供应商, 路由, 用量, 会话, 资源库, 分组, 方案 …). - Every user-visible string in the TUI goes through tr/trf; widths that counted runes (Library's name column, sessions' columns) use lipgloss.Width, so 共享指令 is no longer cut to 共…. - Names stay names: agent and model ids, flags, commands, and the field labels magpie/ultracode/harness/opus/sonnet/haiku/fable. TestEveryWordHasZh reads the TUI's source (every tr/trf literal, every hints label, the tables shown through tr, agent field labels) and fails on a word with no zh, on a zh format that takes the English one's arguments badly, and on a zh entry no longer shown. Not changed: the CLI's own output is still English (#6649). Run: - mica (macOS): go vet ./internal/uilang ./internal/gui ./internal/tui; go test -count=1 -timeout 45m ./... was still running when this was pushed (pushed on the coordinator's ask); its result goes on #6649. - wsl-run (Linux): go vet + go test ./internal/tui ./internal/uilang ok; GOOS=windows go vet ./internal/uilang ./internal/gui ./internal/tui ok; GOOS=darwin CGO_ENABLED=0 go vet ./internal/uilang ./internal/tui ok. - Real TUI (go build -tags nogui) in WSL magpie-desktop, sandbox HOME with settings.json {"lang":"zh"}, tmux 150x40: every page (Agents, Providers, Routing, Usage, Sessions, Library), the add-provider picker, sessions stats, the gateway line and footers read in Chinese. The Library row showed 共… before the lipgloss.Width fix, 共享指令 after. - Broken by hand: an added tr("zzz untranslated") and a zh format with its %s dropped each turned TestEveryWordHasZh red. Not tried: zh-TW, ja and de wording (they fall back as above); the TUI on Windows' console.
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
//go:build !darwin && !windows
|
||||
|
||||
package gui
|
||||
|
||||
import "os"
|
||||
|
||||
// systemLang is the system's language, as the environment names it.
|
||||
func systemLang() string { return envLang(os.Getenv) }
|
||||
@@ -2,9 +2,9 @@ package gui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/yetone/magpie/internal/gateway"
|
||||
"github.com/yetone/magpie/internal/uilang"
|
||||
)
|
||||
|
||||
// trayZh is the tray menu in Chinese; the page has its own words
|
||||
@@ -157,38 +157,12 @@ var trayWords = map[string]map[string]string{"zh": trayZh, "zh-TW": trayZhTW, "j
|
||||
// language; set by the process that has the tray.
|
||||
var onLang func()
|
||||
|
||||
// trayLang is the language the tray menu is in, as the page picks its own:
|
||||
// the setting, or with "system" (or none) the system's: Traditional Chinese
|
||||
// for Taiwan, Hong Kong, Macau and any zh-Hant (zh_TW.UTF-8, zh-Hant-TW),
|
||||
// Simplified for any other zh, Japanese for any ja, German for any de.
|
||||
func trayLang(pref string, system func() string) string {
|
||||
switch pref {
|
||||
case "en", "zh", "zh-TW", "ja", "de":
|
||||
return pref
|
||||
}
|
||||
switch sys := strings.ReplaceAll(strings.ToLower(system()), "_", "-"); {
|
||||
case zhTraditional(sys):
|
||||
return "zh-TW"
|
||||
case strings.HasPrefix(sys, "zh"):
|
||||
return "zh"
|
||||
case strings.HasPrefix(sys, "ja"):
|
||||
return "ja"
|
||||
case strings.HasPrefix(sys, "de"):
|
||||
return "de"
|
||||
}
|
||||
return "en"
|
||||
}
|
||||
// trayLang is the language the tray menu is in, as the page picks its own
|
||||
// (uilang.Pick).
|
||||
func trayLang(pref string, system func() string) string { return uilang.Pick(pref, system) }
|
||||
|
||||
// zhTraditional says a lowercased, dashed system tag is Traditional
|
||||
// Chinese, as the page's sysLocale does.
|
||||
func zhTraditional(sys string) bool {
|
||||
for _, p := range []string{"zh-tw", "zh-hk", "zh-mo", "zh-hant"} {
|
||||
if sys == p || strings.HasPrefix(sys, p+"-") || strings.HasPrefix(sys, p+".") || strings.HasPrefix(sys, p+"@") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
// systemLang is the system's language (uilang.System).
|
||||
func systemLang() string { return uilang.System() }
|
||||
|
||||
// notesLang is the language release notes are asked in for lang: there are
|
||||
// no German ones, so German asks for the English, and Traditional Chinese
|
||||
@@ -246,26 +220,3 @@ func trayRestartNow(lang string, b gateway.Busy) string {
|
||||
}
|
||||
return trayText(lang, "Restart Now to Update")
|
||||
}
|
||||
|
||||
// envLang is the language the environment names: the first of LC_ALL,
|
||||
// LC_MESSAGES, LANG and LANGUAGE set to one.
|
||||
func envLang(getenv func(string) string) string {
|
||||
for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG", "LANGUAGE"} {
|
||||
if v := getenv(k); v != "" && v != "C" && v != "POSIX" && !strings.HasPrefix(v, "C.") {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// firstAppleLang is the first entry `defaults read -g AppleLanguages`
|
||||
// prints: ( "zh-Hans-CN", "en-US" ), one to a line, quoted or not.
|
||||
func firstAppleLang(out string) string {
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
s := strings.Trim(strings.TrimSpace(line), `",`)
|
||||
if s != "" && s != "(" && s != ")" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
@@ -78,16 +78,6 @@ func TestTrayMenuLabels(t *testing.T) {
|
||||
t.Errorf("%s paused: %q, want %q", lang, l.pause, want)
|
||||
}
|
||||
}
|
||||
env := map[string]string{"LC_ALL": "C", "LANG": "zh_CN.UTF-8"}
|
||||
if got := envLang(func(k string) string { return env[k] }); got != "zh_CN.UTF-8" {
|
||||
t.Errorf("envLang skips C: %q", got)
|
||||
}
|
||||
if got := firstAppleLang("(\n \"zh-Hans-CN\",\n \"en-US\"\n)\n"); got != "zh-Hans-CN" {
|
||||
t.Errorf("firstAppleLang: %q", got)
|
||||
}
|
||||
if got := firstAppleLang("(\n en,\n \"zh-Hans\"\n)\n"); got != "en" {
|
||||
t.Errorf("firstAppleLang unquoted: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
// A language changed on the Settings page relabels the tray menu; a save
|
||||
|
||||
@@ -82,15 +82,15 @@ func serveGateway(ctx context.Context) (wait func()) {
|
||||
// nothing else to say: served here, or why agents can't reach it.
|
||||
func gatewayStatus() string {
|
||||
if gw.here.Load() {
|
||||
return sMuted.Render("● gateway " + gateway.URL() + " · served while magpie tui is open")
|
||||
return sMuted.Render("● " + trf("gateway %s · served while magpie tui is open", gateway.URL()))
|
||||
}
|
||||
if e := gw.err.Load(); e != nil && *e != "" {
|
||||
return sBad.Render("✗ ") + sText.Render("gateway not running: "+*e)
|
||||
return sBad.Render("✗ ") + sText.Render(trf("gateway not running: %s", *e))
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// gatewayGoneNote is said as the terminal quits having served the gateway.
|
||||
func gatewayGoneNote() string {
|
||||
return "magpie: the gateway stopped with magpie tui; agents connected to magpie reach it while magpie tui, magpie web or magpie serve runs"
|
||||
return tr("magpie: the gateway stopped with magpie tui; agents connected to magpie reach it while magpie tui, magpie web or magpie serve runs")
|
||||
}
|
||||
|
||||
@@ -0,0 +1,515 @@
|
||||
package tui
|
||||
|
||||
// The TUI speaks the language the GUI is set to (zaidu259434 on X asked
|
||||
// why it was English only). Each word it shows is a key in the table
|
||||
// below, the English itself; TestEveryWordHasZh fails on one that isn't.
|
||||
|
||||
import "fmt"
|
||||
|
||||
// lang is the language the TUI speaks, set once as Run starts from the
|
||||
// GUI's setting (settings.Lang, through uilang.Pick). Tests leave it "en".
|
||||
var lang = "en"
|
||||
|
||||
// speak is the table lang reads: the TUI has Simplified Chinese only, so
|
||||
// Traditional Chinese reads it too, and Japanese and German read English.
|
||||
func speak(l string) string {
|
||||
if l == "zh-TW" {
|
||||
return "zh"
|
||||
}
|
||||
if _, ok := words[l]; ok {
|
||||
return l
|
||||
}
|
||||
return "en"
|
||||
}
|
||||
|
||||
// tr is s in the TUI's language: s itself, the English, when the table
|
||||
// has no word for it.
|
||||
func tr(s string) string {
|
||||
if w, ok := words[lang][s]; ok {
|
||||
return w
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// trf is tr's format, filled in: the translated format keeps the
|
||||
// English one's verbs (%[n]s to reorder them).
|
||||
func trf(format string, args ...any) string {
|
||||
return fmt.Sprintf(tr(format), args...)
|
||||
}
|
||||
|
||||
// words is each language's table, keyed by the English. The zh words
|
||||
// follow the GUI's (internal/gui/assets/i18n.js) where both say the same.
|
||||
var words = map[string]map[string]string{"zh": zh}
|
||||
|
||||
var zh = map[string]string{
|
||||
"gateway %s · served while magpie tui is open": "网关 %s · magpie tui 开着时由它提供",
|
||||
"gateway not running: %s": "网关未运行:%s",
|
||||
"magpie: the gateway stopped with magpie tui; agents connected to magpie reach it while magpie tui, magpie web or magpie serve runs": "magpie:网关随 magpie tui 一起停了;接入 magpie 的 Agent 在 magpie tui、magpie web 或 magpie serve 运行时才能连上",
|
||||
"magpie: the gateway goes on in magpie's service (magpie daemon status)": "magpie:网关在 magpie 的服务里继续运行(magpie daemon status)",
|
||||
"magpie: the gateway goes on in magpie's service, which now starts with this system or your login, so agents connected to magpie reach it with magpie tui closed; magpie daemon uninstall removes it": "magpie:网关在 magpie 的服务里继续运行,它现在随系统或登录启动,所以关掉 magpie tui 后接入 magpie 的 Agent 仍能连上;magpie daemon uninstall 可移除",
|
||||
"(couldn't start magpie serve in the background: %s)": "(无法在后台启动 magpie serve:%s)",
|
||||
"magpie: the gateway goes on in the background (magpie serve, pid %d, log %s) until this system stops": "magpie:网关在后台继续运行(magpie serve,pid %d,日志 %s),直到系统关闭",
|
||||
"; for it to start with WSL, turn systemd on with [boot] systemd=true in /etc/wsl.conf and run magpie daemon install": ";要让它随 WSL 启动,在 /etc/wsl.conf 里用 [boot] systemd=true 开启 systemd,再运行 magpie daemon install",
|
||||
"; magpie daemon install starts it with the system": ";magpie daemon install 让它随系统启动",
|
||||
"; magpie opens at login and serves it then. Where no desktop logs in here, `magpie autostart off` has magpie tui hand it on as it quits": ";magpie 会在登录时打开并提供网关。如果这里没有桌面登录,`magpie autostart off` 让 magpie tui 退出时把网关交出去",
|
||||
"shared instructions": "共享指令",
|
||||
"none yet · e writes them": "还没有 · e 编写",
|
||||
"%d line%s": "%d 行%s",
|
||||
"not synced": "不同步",
|
||||
"its folder is gone": "它的文件夹已不存在",
|
||||
"removed from %s · d takes it out": "已从 %s 移除 · d 将其删除",
|
||||
"off on this computer · magpie library skill on-here %s": "在这台电脑上已关闭 · magpie library skill on-here %s",
|
||||
"not installed": "未安装",
|
||||
"%s · %s tokens saved": "%s · 已节省 %s token",
|
||||
"writing the library into the agents…": "正在把资源库写入各 Agent…",
|
||||
"synced": "已同步",
|
||||
"i brings %s into the library, for magpie to give it to other agents too": "i 把 %s 导入资源库,magpie 也能把它给其他 Agent",
|
||||
"d takes it out of every agent that has it": "d 把它从所有使用它的 Agent 中移除",
|
||||
"fetching %s from GitHub again…": "正在从 GitHub 重新获取 %s…",
|
||||
"d takes it out": "d 将其移除",
|
||||
"updated %s": "已更新 %s",
|
||||
"%s is put there by the agent's app itself, each time it starts: it stays as it is": "%s 由 Agent 自己的 App 在每次启动时放入:保持原样",
|
||||
"brought %s into the library": "已把 %s 导入资源库",
|
||||
"press d again to take %s out of the library and every agent": "再按一次 d,把 %s 从资源库和所有 Agent 中移除",
|
||||
"press d again to take %s out of every agent that has it, kept with the backups": "再按一次 d,把 %s 从所有使用它的 Agent 中移除,保留在备份里",
|
||||
"press d again to take %s out of every agent that has it, their files kept with the backups": "再按一次 d,把 %s 从所有使用它的 Agent 中移除,文件保留在备份里",
|
||||
"removed %s": "已移除 %s",
|
||||
"%s in the library already": "%s 已在资源库中",
|
||||
"%s updates from GitHub now": "%s 现在从 GitHub 更新",
|
||||
"files of their own kept with the backups: %s": "各自的文件已保留在备份里:%s",
|
||||
"%s skipped: %s": "已跳过 %s:%s",
|
||||
"written into %s": "已写入 %s",
|
||||
"off": "关闭",
|
||||
"on": "开启",
|
||||
"library": "资源库",
|
||||
"agents": "Agent",
|
||||
"filter agents": "筛选 Agent",
|
||||
"no agent here has a place for it": "这里没有 Agent 能放它",
|
||||
"RTK %s for %s": "RTK %s 用于 %s",
|
||||
"restart %s for it to take effect": "重启 %s 后生效",
|
||||
"%s given to %s": "已把 %s 给 %s",
|
||||
"%s taken from %s": "已从 %[2]s 拿走 %[1]s",
|
||||
"add": "添加",
|
||||
"filter": "筛选",
|
||||
"mcp server": "MCP 服务器",
|
||||
"a URL, or a command it runs": "一个 URL,或它运行的命令",
|
||||
"skills": "技能",
|
||||
"from GitHub, GitLab or any git repository, or a folder on this machine": "来自 GitHub、GitLab 或任意 git 仓库,或本机的文件夹",
|
||||
"owner/repo, a GitHub or GitLab link, a git address (git@host:group/repo.git), or a folder's full path": "owner/repo、GitHub 或 GitLab 链接、git 地址(git@host:group/repo.git),或文件夹的完整路径",
|
||||
"magpie looks there for skills, then you pick one": "magpie 在那里查找技能,然后由你挑选",
|
||||
"<name> <url | command args…>": "<名称> <url | 命令 参数…>",
|
||||
"e.g. %s": "例如 %s",
|
||||
"then ↵ on it gives it to agents": "然后在它上面按 ↵ 把它给 Agent",
|
||||
"edit": "编辑",
|
||||
"its env, headers and agents stay as they are": "它的环境变量、请求头和 Agent 保持不变",
|
||||
"a name, then a URL or a command": "一个名称,然后是 URL 或命令",
|
||||
"added %s · ↵ on it gives it to agents": "已添加 %s · 在它上面按 ↵ 把它给 Agent",
|
||||
"saved %s": "已保存 %s",
|
||||
"in the library as %s": "在资源库中名为 %s",
|
||||
"in the library already": "已在资源库中",
|
||||
"links the library's to GitHub": "把资源库里的关联到 GitHub",
|
||||
"adds as %s": "以 %s 添加",
|
||||
"filter skills": "筛选技能",
|
||||
"no skills there: a skill is a folder with a SKILL.md": "那里没有技能:技能是一个带 SKILL.md 的文件夹",
|
||||
"added the skill · ↵ on it gives it to agents": "已添加技能 · 在它上面按 ↵ 把它给 Agent",
|
||||
"too big to install, over 200 MB a skill: %s": "太大无法安装,单个技能超过 200 MB:%s",
|
||||
"the instructions are as they were": "指令保持原样",
|
||||
"instructions saved": "指令已保存",
|
||||
"instructions · what every agent reads before a conversation": "指令 · 每个 Agent 在对话前都会读取",
|
||||
"mcp servers · a adds one, e changes it": "MCP 服务器 · a 添加,e 修改",
|
||||
"skills · a adds some from GitHub or a folder, u fetches one from GitHub again": "技能 · a 从 GitHub 或文件夹添加,u 从 GitHub 重新获取",
|
||||
"mcp servers in your agents, not in the library": "Agent 里有、资源库里没有的 MCP 服务器",
|
||||
"skills in your agents, not in the library": "Agent 里有、资源库里没有的技能",
|
||||
"rtk · its hook in each agent, by RTK's own installer": "rtk · 由 RTK 自己的安装程序装进各 Agent 的钩子",
|
||||
"%s's own": "%s 自带",
|
||||
"no agent": "无 Agent",
|
||||
"kept in %s": "保存在 %s",
|
||||
"balance: %s": "余额:%s",
|
||||
"asking the vendors for balances…": "正在向各厂商查询余额…",
|
||||
"%s is a signed-in account: its key is the agent's sign-in": "%s 是已登录的账号:它的密钥就是 Agent 的登录",
|
||||
"%s takes no key · magpie provider set %s credentials=… impersonate=… changes its Google credentials": "%s 不用密钥 · magpie provider set %s credentials=… impersonate=… 修改它的 Google 凭据",
|
||||
"the API key": "API 密钥",
|
||||
"providers": "供应商",
|
||||
"key": "密钥",
|
||||
"now %s · the key is kept in magpie's providers file": "现在是 %s · 密钥保存在 magpie 的供应商文件里",
|
||||
"%s key %s": "%s 密钥 %s",
|
||||
"%s is asked at your Google Cloud project · magpie provider set %s project=… location=… changes it": "%s 请求发往你的 Google Cloud 项目 · magpie provider set %s project=… location=… 修改",
|
||||
"address": "地址",
|
||||
"%s address unchanged": "%s 地址未变",
|
||||
"%s address %s": "%s 地址 %s",
|
||||
"%s is asked at its vendor's address · magpie provider set %s url=… changes a custom one's": "%s 请求发往厂商的地址 · magpie provider set %s url=… 修改自定义供应商的地址",
|
||||
"a tag, e.g. relay": "一个标签,例如 relay",
|
||||
"family": "家族",
|
||||
"agents can be shown only some families: magpie visible <agent> <family>": "可以只向 Agent 显示部分家族:magpie visible <agent> <family>",
|
||||
"%s family %s": "%s 家族 %s",
|
||||
"its models are listed": "列出它的模型",
|
||||
"serves only through routing groups": "只通过路由分组提供",
|
||||
"switched on": "已开启",
|
||||
"switched off: agents are given none of its models": "已关闭:不给 Agent 它的任何模型",
|
||||
"testing %s…": "正在测试 %s…",
|
||||
"asking %s for its models…": "正在向 %s 获取模型…",
|
||||
"press d again to remove %s": "再按一次 d 移除 %s",
|
||||
"moved %s": "已移动 %s",
|
||||
"%s's models are what its plugin lists": "%s 的模型以它的插件所列为准",
|
||||
"gone from its list, so no longer picked: %s": "已不在它的列表里,不再选用:%s",
|
||||
"%d models from its list": "它的列表中有 %d 个模型",
|
||||
"%d for agents (↵ picks)": "%d 个给 Agent(↵ 选择)",
|
||||
"no model list · %s · m asks again": "没有模型列表 · %s · m 重新获取",
|
||||
"nothing to test": "没有可测试的",
|
||||
"models": "模型",
|
||||
"filter models": "筛选模型",
|
||||
"no models known yet · ctrl+r asks the vendor for them": "还不知道有哪些模型 · ctrl+r 向厂商获取",
|
||||
"one model has to stay on": "至少要保留一个模型开启",
|
||||
"another computer's magpie, shared on its network": "另一台电脑上的 magpie,局域网共享",
|
||||
"vendor": "厂商",
|
||||
"relay": "中转",
|
||||
"local": "本地",
|
||||
"partner": "合作伙伴",
|
||||
"partner (sponsor)": "合作伙伴(赞助商)",
|
||||
"your own · %s API, at its address": "自定义 · %s API,在它的地址上",
|
||||
"a vendor magpie knows, or custom for your own API": "magpie 认识的厂商,或自定义你自己的 API",
|
||||
"custom": "自定义",
|
||||
"base URL": "API 地址",
|
||||
"the base URL, e.g. %s": "API 地址,例如 %s",
|
||||
"the base URL is an http:// or https:// address, e.g. %s": "API 地址需以 http:// 或 https:// 开头,例如 %s",
|
||||
"name": "名称",
|
||||
"its name in magpie · enter for %s": "它在 magpie 中的名称 · 回车用 %s",
|
||||
"enter keeps it": "回车保持不变",
|
||||
"%s base URL unchanged": "%s API 地址未变",
|
||||
"%s base URL %s": "%s API 地址 %s",
|
||||
"the key is kept in magpie's providers file": "密钥保存在 magpie 的供应商文件里",
|
||||
"keys: %s": "密钥:%s",
|
||||
"project": "项目",
|
||||
"your Google Cloud project's id": "你的 Google Cloud 项目 ID",
|
||||
"no key: signed with gcloud's Application Default Credentials (gcloud auth application-default login)": "无密钥:用 gcloud 的应用默认凭据签名(gcloud auth application-default login)",
|
||||
"magpie provider set %s location=… credentials=… impersonate=… changes the rest": "magpie provider set %s location=… credentials=… impersonate=… 修改其余设置",
|
||||
"added %s": "已添加 %s",
|
||||
"the address it is reached at, e.g. %s": "访问它的地址,例如 %s",
|
||||
"Your resource's endpoint is needed": "需要填写你的资源接口地址",
|
||||
"where the server listens: another port, or another computer's address": "服务监听的地方:另一个端口,或另一台电脑的地址",
|
||||
"no providers yet · a adds one": "还没有供应商 · a 添加",
|
||||
"switched off": "已关闭",
|
||||
"%s is signed out": "%s 已退出登录",
|
||||
"needs a project": "需要项目",
|
||||
"Google credentials": "Google 凭据",
|
||||
"as %s": "身份 %s",
|
||||
"no key needed": "无需密钥",
|
||||
"no key": "无密钥",
|
||||
"%d models": "%d 个模型",
|
||||
"o switches it on": "o 开启它",
|
||||
"family %s": "家族 %s",
|
||||
"groups only": "仅分组",
|
||||
"couldn't list its models: %s": "无法列出它的模型:%s",
|
||||
"no WorkBuddy (China), Trae CN, MiniMax Code, Qoder or check-in plugin account is signed in · only they have the daily check-in": "没有登录 WorkBuddy(国内版)、Trae CN、MiniMax Code、Qoder 或签到插件的账号 · 只有它们有每日签到",
|
||||
"%s checked in today": "%s 今天已签到",
|
||||
"a %d-day streak": "连续 %d 天",
|
||||
"already": "已经签过",
|
||||
"%s isn't eligible for the check-in": "%s 不符合签到条件",
|
||||
"no check-in event now": "当前没有签到活动",
|
||||
"%s asks for a captcha: check in in its own app": "%s 需要验证码:请在它自己的 App 里签到",
|
||||
"no answer": "无响应",
|
||||
"%s couldn't check in: %s": "%s 签到失败:%s",
|
||||
"says already checked in · its day may not have turned, magpie asks again later": "显示已签到 · 它那边可能还没到第二天,magpie 稍后再试",
|
||||
"not eligible now · magpie asks again later": "当前不符合条件 · magpie 稍后再试",
|
||||
"no check-in event now · magpie asks again later": "当前没有签到活动 · magpie 稍后再试",
|
||||
"the vendor": "该厂商",
|
||||
"%[1]s only gives check-in credits to its own app; check in in the %[1]s app": "%[1]s 只给自己的 App 发签到额度;请在 %[1]s App 里签到",
|
||||
"c says why": "c 查看原因",
|
||||
"签到 not yet today · c": "签到 今天还没签 · c",
|
||||
"签到 said already · asked again later · c": "签到 显示已签 · 稍后再试 · c",
|
||||
"%d-day streak": "连续 %d 天",
|
||||
"签到 not eligible": "签到 不符合条件",
|
||||
"签到 no event now": "签到 当前没有活动",
|
||||
"签到 needs a captcha · check in in its app": "签到 需要验证码 · 请在它的 App 里签到",
|
||||
"签到 refused by Trae CN (9074) · check in in its app": "签到 被 Trae CN 拒绝(9074)· 请在它的 App 里签到",
|
||||
"签到 only in %s's own app · check in there": "签到 只能在 %s 自己的 App 里签 · 请到那里签到",
|
||||
"签到 failed": "签到 失败",
|
||||
"c tries again": "c 重试",
|
||||
"checking in…": "正在签到…",
|
||||
"no price": "无价格",
|
||||
"no calls in this time · route an agent through magpie and its usage shows up here": "这段时间没有调用 · 让 Agent 通过 magpie 路由,用量就会显示在这里",
|
||||
"no calls through magpie in this time": "这段时间没有经过 magpie 的调用",
|
||||
"not through magpie · the agents' own requests, read from their session files": "不经过 magpie · Agent 自己的请求,读自它们的会话文件",
|
||||
"%s tokens": "%s token",
|
||||
"%d call%s": "%d 次调用%s",
|
||||
"(%d call%s unpriced)": "(%d 次调用%s无价格)",
|
||||
"%d error%s": "%d 个错误%s",
|
||||
"%d answered on a retry": "%d 次靠重试得到回复",
|
||||
"in %s out %s cache read %s cache write %s reasoning %s": "输入 %s 输出 %s 缓存读取 %s 缓存写入 %s 推理 %s",
|
||||
"and %d more · magpie usage": "另有 %d 个 · magpie usage",
|
||||
"accounts": "账号",
|
||||
"asking the vendors what is left…": "正在向各厂商查询剩余额度…",
|
||||
"accounts · % is how much is used": "账号 · % 为已用比例",
|
||||
"accounts · % is how much is left": "账号 · % 为剩余比例",
|
||||
"left": "剩余",
|
||||
"no usage reported": "未报告用量",
|
||||
"not spent": "未使用",
|
||||
"until %s": "直到 %s",
|
||||
"Unlimited": "无限",
|
||||
"used": "已用",
|
||||
"%dm": "%d分钟",
|
||||
"%dh": "%d小时",
|
||||
"%dd": "%d天",
|
||||
"in order": "按顺序",
|
||||
"rotate": "轮换",
|
||||
"least used": "最少使用",
|
||||
"weekly pace": "按周均匀",
|
||||
"by weight": "按权重",
|
||||
"free first": "免费优先",
|
||||
"speed first": "速度优先",
|
||||
"cheapest first": "最便宜优先",
|
||||
"until used up": "用完再换",
|
||||
"free, soonest to expire": "免费且最快到期优先",
|
||||
"manual": "手动",
|
||||
"smart": "智能",
|
||||
"stays the session": "整个会话保持",
|
||||
"stays a turn": "单轮保持",
|
||||
"never stays": "不保持",
|
||||
"stays strictly": "严格保持",
|
||||
"stays auto": "自动保持",
|
||||
"no group %s": "没有分组 %s",
|
||||
"routing": "路由",
|
||||
"new": "新建",
|
||||
"the group's name, e.g. opus-anywhere": "分组名称,例如 opus-anywhere",
|
||||
"then pick its first model; agents choose it as group/<id>": "然后挑选它的第一个模型;Agent 以 group/<id> 选用它",
|
||||
"brought %s back": "已恢复 %s",
|
||||
"%s was removed · u brings it back": "%s 已移除 · u 恢复",
|
||||
"%s routing changed": "%s 路由方式已修改",
|
||||
"group": "分组",
|
||||
"decision model": "决策模型",
|
||||
"first model": "第一个模型",
|
||||
"magpie has no models yet · add a provider first": "magpie 还没有模型 · 请先添加供应商",
|
||||
"add a model": "添加模型",
|
||||
"every model magpie has is in it": "magpie 的所有模型都已在其中",
|
||||
"filter models and groups": "筛选模型和分组",
|
||||
"%s added": "已添加 %s",
|
||||
"made group %s · ↵ on it adds more models": "已创建分组 %s · 在它上面按 ↵ 添加更多模型",
|
||||
"now": "当前",
|
||||
"classifier": "分类模型",
|
||||
"filter models · best a small fast one without reasoning": "筛选模型 · 最好选一个不带推理的小而快的模型",
|
||||
"%s classifies with %s": "%s 用 %s 分类",
|
||||
"new rule": "新规则",
|
||||
"rule %d": "规则 %d",
|
||||
"its models: %s": "它的模型:%s",
|
||||
"rule added": "已添加规则",
|
||||
"rule %d changed": "规则 %d 已修改",
|
||||
"rule %d moved to %d": "规则 %d 已移到 %d",
|
||||
"%s moved": "已移动 %s",
|
||||
"%s has no rule with an intent to classify for · n adds one": "%s 没有需要分类意图的规则 · n 添加",
|
||||
"%s not fast": "%s 非快速",
|
||||
"%s fast": "%s 快速",
|
||||
"%s set": "已设为 %s",
|
||||
"%s affinity changed": "%s 会话保持已修改",
|
||||
"your own word on it, e.g. office key only": "你自己的备注,例如 仅限办公室密钥",
|
||||
"note": "备注",
|
||||
"shown under its name; empty clears it": "显示在名称下方;留空即清除",
|
||||
"%s note %s": "%s 备注 %s",
|
||||
"tokens, e.g. 200k · empty for its models' own": "token 数,例如 200k · 留空则用其模型自己的",
|
||||
"context": "上下文",
|
||||
"how long a request agents are told the group takes, rather than its largest model's": "告诉 Agent 这个分组能接受多长的请求,而不是用其中最大模型的",
|
||||
"%s context %s": "%s 上下文 %s",
|
||||
"e.g. low,medium,high,xhigh · empty for those its models share": "例如 low,medium,high,xhigh · 留空则用其模型共有的",
|
||||
"levels": "推理档位",
|
||||
"the reasoning levels agents are offered: %s; a model without the one asked is sent its nearest": "提供给 Agent 的推理档位:%s;模型没有所要的档位时,发送最接近的",
|
||||
"%s levels %s": "%s 推理档位 %s",
|
||||
"the group's new id": "分组的新 id",
|
||||
"rename": "重命名",
|
||||
"agents pick it as group/<id>: those on it, and the groups that have it in them, follow": "Agent 以 group/<id> 选用它:用着它的 Agent 和包含它的分组都会跟着改",
|
||||
"press d again to remove rule %d": "再按一次 d 删除规则 %d",
|
||||
"rule %d removed": "规则 %d 已删除",
|
||||
"a group needs a model in it · d on the routing list removes the group": "分组里至少要有一个模型 · 在路由列表上按 d 删除分组",
|
||||
"press d again to take %s out": "再按一次 d 移出 %s",
|
||||
" and its rules": "及其规则",
|
||||
"%s taken out": "已移出 %s",
|
||||
"no routing groups yet · n makes one": "还没有路由分组 · n 新建",
|
||||
"removed · found by magpie, taken away: u brings one back": "已移除 · 由 magpie 发现、被拿掉的分组:u 恢复",
|
||||
"%d model%s": "%d 个模型%s",
|
||||
"%d switched off": "%d 个已关闭",
|
||||
"%d rule%s": "%d 条规则%s",
|
||||
"found": "已发现",
|
||||
"%d pattern%s": "%d 个模式%s",
|
||||
"context %s": "上下文 %s",
|
||||
"levels %s": "推理档位 %s",
|
||||
"found by magpie: a change makes it yours": "由 magpie 发现:修改后归你所有",
|
||||
"models · the first that can take a request gets it": "模型 · 由第一个能接受请求的模型处理",
|
||||
"fast": "快速",
|
||||
"by pattern": "按模式匹配",
|
||||
"switched off: skipped until it is on again": "已关闭:开启前会被跳过",
|
||||
"patterns · every model they match now, after those named": "模式 · 在列出的模型之后,当前匹配到的所有模型",
|
||||
"matches nothing now": "目前没有匹配的模型",
|
||||
"rules · as a turn begins, the first that matches sends it to its model first; a pause leaves its model out while it holds": "规则 · 每轮开始时,第一条匹配的规则先把请求发给它的模型;暂停规则在生效期间排除它的模型",
|
||||
"none · n adds one": "无 · n 添加",
|
||||
"pause": "暂停",
|
||||
"at": "在",
|
||||
"tells which intent a message is": "判断消息属于哪种意图",
|
||||
"magpie reads no agent's session history until you allow it · magpie sessions read on all (or on <agent>), or the app's Sessions page": "你允许之前,magpie 不读取任何 Agent 的会话历史 · magpie sessions read on all(或 on <agent>),或在 App 的会话页面开启",
|
||||
"nothing in this range · Claude Code's, Codex's, OpenCode's and Pi's sessions on this computer show up here": "这个范围内没有内容 · 这台电脑上 Claude Code、Codex、OpenCode 和 Pi 的会话会显示在这里",
|
||||
"this session can't be resumed from here": "这个会话无法在这里继续",
|
||||
"its folder %s isn't there any more": "它的文件夹 %s 已不存在",
|
||||
"resume: %s": "继续会话:%s",
|
||||
"back from the session": "已从会话返回",
|
||||
"model": "模型",
|
||||
"folder": "文件夹",
|
||||
"sessions": "会话",
|
||||
"stats": "统计",
|
||||
"no session matches · x clears the filters": "没有匹配的会话 · x 清除筛选",
|
||||
"(untitled)": "(无标题)",
|
||||
"↑ %d more": "↑ 还有 %d 个",
|
||||
"↓ %d more": "↓ 还有 %d 个",
|
||||
"↵ runs %s": "↵ 运行 %s",
|
||||
"just now": "刚刚",
|
||||
"%dm ago": "%d分钟前",
|
||||
"%dh ago": "%d小时前",
|
||||
"%dd ago": "%d天前",
|
||||
"(%s hit)": "(命中 %s)",
|
||||
"on %d day%s": "用了 %d 天%s",
|
||||
"not kept by model": "不按模型统计",
|
||||
"cache read": "缓存读取",
|
||||
"active": "活跃时长",
|
||||
"in %s out %s cache write %s": "输入 %s 输出 %s 缓存写入 %s",
|
||||
"and %d more · f and M pick one": "另有 %d 个 · f 和 M 挑选",
|
||||
"(no folder)": "(无文件夹)",
|
||||
"a day": "每天",
|
||||
"a week": "每周",
|
||||
"%d days": "每 %d 天",
|
||||
"Jan 2": "1月2日",
|
||||
"no supported agents found on this machine": "这台电脑上没有找到支持的 Agent",
|
||||
"group/%s is group/%s now": "group/%s 现在是 group/%s",
|
||||
"catalog sync failed: %s": "模型目录同步失败:%s",
|
||||
"model catalog synced from models.dev": "已从 models.dev 同步模型目录",
|
||||
"reloaded": "已重新加载",
|
||||
"profile name": "方案名称",
|
||||
"type to filter, or enter a custom value": "输入以筛选,或输入自定义值",
|
||||
"no models known yet, type one": "还不知道有哪些模型,请输入一个",
|
||||
"in use": "使用中",
|
||||
"profiles": "方案",
|
||||
"filter profiles": "筛选方案",
|
||||
"no profiles yet · press s in the list to save one": "还没有方案 · 在列表里按 s 保存一个",
|
||||
"profile %s applied · %d change%s": "已应用方案 %s · %d 处修改%s",
|
||||
"profile %s deleted": "已删除方案 %s",
|
||||
"asking for the models again…": "正在重新获取模型…",
|
||||
"new name": "新名称",
|
||||
"profile %s renamed to %s": "方案 %s 已重命名为 %s",
|
||||
"saved profile %s": "已保存方案 %s",
|
||||
"current": "在用",
|
||||
"syncing model catalog": "正在同步模型目录",
|
||||
"↵ use %s as a custom value": "↵ 使用自定义值 %s",
|
||||
"no match": "没有匹配项",
|
||||
"rename profile": "重命名方案",
|
||||
"renames %s · the settings it holds stay as they are": "重命名 %s · 它保存的设置不变",
|
||||
"save profile": "保存方案",
|
||||
"snapshots every agent's current settings": "保存每个 Agent 当前设置的快照",
|
||||
"provider": "供应商",
|
||||
"list/groups only": "仅列表/分组",
|
||||
"on/off": "开/关",
|
||||
"fetch models": "获取模型",
|
||||
"test": "测试",
|
||||
"balances": "余额",
|
||||
"remove": "移除",
|
||||
"pages": "页面",
|
||||
"open": "打开",
|
||||
"bring back": "恢复",
|
||||
"quit": "退出",
|
||||
"item": "条目",
|
||||
"update skill": "更新技能",
|
||||
"bring in": "导入",
|
||||
"sync": "同步",
|
||||
"reload": "重新加载",
|
||||
"range": "范围",
|
||||
"clear": "清除筛选",
|
||||
"tokens / cost": "token / 费用",
|
||||
"session": "会话",
|
||||
"resume": "继续",
|
||||
"period": "时段",
|
||||
"today · 7 days · 30 days · all": "今天 · 7 天 · 30 天 · 全部",
|
||||
"used / left": "已用 / 剩余",
|
||||
"daily check-in": "每日自动签到",
|
||||
"agent": "Agent",
|
||||
"field": "字段",
|
||||
"change": "修改",
|
||||
"move": "移动",
|
||||
"apply": "应用",
|
||||
"delete": "删除",
|
||||
"back": "返回",
|
||||
"on / off": "开 / 关",
|
||||
"fetch models again": "重新获取模型",
|
||||
"select": "选择",
|
||||
"save": "保存",
|
||||
"cancel": "取消",
|
||||
"model / rule": "模型 / 规则",
|
||||
"add model": "添加模型",
|
||||
"edit rule": "编辑规则",
|
||||
"take out": "移出",
|
||||
"effort": "推理强度",
|
||||
"stays": "会话保持",
|
||||
"usage": "用量",
|
||||
"today": "今天",
|
||||
"7 days": "7 天",
|
||||
"30 days": "30 天",
|
||||
"all time": "全部时间",
|
||||
"90 days": "90 天",
|
||||
"all": "全部",
|
||||
"all models": "全部模型",
|
||||
"all folders": "全部文件夹",
|
||||
"OpenAI compatible (Chat Completions)": "OpenAI 兼容(Chat Completions)",
|
||||
"OpenAI Responses": "OpenAI Responses",
|
||||
"Anthropic compatible (Messages)": "Anthropic 兼容(Messages)",
|
||||
"Gemini compatible": "Gemini 兼容",
|
||||
"folders": "文件夹",
|
||||
"tokens": "token",
|
||||
"cost": "费用",
|
||||
"Trae CN refused this check-in (9074: too many taking part); check in in the Trae CN app": "Trae CN 拒绝了这次签到(9074 当前参与用户太多),请在 Trae CN App 里签到",
|
||||
"thinking": "思考",
|
||||
"small": "小模型",
|
||||
"subagents": "子代理",
|
||||
"subagent model": "子代理模型",
|
||||
"subagent effort": "子代理推理强度",
|
||||
"sign-in": "登录方式",
|
||||
"compaction model": "压缩模型",
|
||||
"status line": "状态栏",
|
||||
"protocol": "协议",
|
||||
"planner": "规划模型",
|
||||
"memories": "记忆整理模型",
|
||||
"large": "大模型",
|
||||
"gateway": "网关",
|
||||
"auth": "认证",
|
||||
"applies to": "适用范围",
|
||||
"advisor review": "顾问审查",
|
||||
"advisor model": "顾问模型",
|
||||
"account": "账号",
|
||||
"auto mode": "自动模式",
|
||||
"opus effort": "opus 推理强度",
|
||||
"sonnet effort": "sonnet 推理强度",
|
||||
"haiku effort": "haiku 推理强度",
|
||||
"fable effort": "fable 推理强度",
|
||||
"image": "图片",
|
||||
"standard": "标准",
|
||||
"deep": "深度",
|
||||
"visual": "视觉",
|
||||
"executor": "执行模型",
|
||||
"subagents thinking": "子代理思考",
|
||||
"smol": "小模型",
|
||||
"smol thinking": "小模型思考",
|
||||
"slow": "慢模型",
|
||||
"slow thinking": "慢模型思考",
|
||||
"plan": "规划",
|
||||
"plan thinking": "规划思考",
|
||||
"vision": "视觉",
|
||||
"vision thinking": "视觉思考",
|
||||
"advisor": "顾问",
|
||||
"advisor thinking": "顾问思考",
|
||||
"commit": "提交",
|
||||
"commit thinking": "提交思考",
|
||||
"tiny": "微模型",
|
||||
"tiny thinking": "微模型思考",
|
||||
"memory": "记忆",
|
||||
"memory thinking": "记忆思考",
|
||||
"advisor wait": "顾问等待",
|
||||
"advisor wakes on": "顾问唤醒时机",
|
||||
ruleHint: `use=<模型>,再加任意几项:tokens=200k · images · effort=on|low|medium|high|xhigh|max · agents=codex,claude
|
||||
intent="一个简单问题"(由分组的 classifier=<模型> 判断)· compact
|
||||
time=09:00-18:00(22:00-08:00 跨过午夜)· days=mon-fri · tz=Asia/Shanghai(不填则用这台电脑的时区)· folders=~/work/acme,~/oss · except-folders=~/old · at=<n> 指定它的位置
|
||||
when="effort is not off" · when="tokens < 20k" · when="agent is not codex" · when=subagent · when="message contains …" · when="system matches ^You are a title"
|
||||
use-effort=low|medium|high|xhigh|max:不管 Agent 要求什么,都以这个推理强度请求模型
|
||||
或 pause=<模型> time=… days=… agents=… folders=… except-folders=…:届时把该模型排除在分组之外,连回退也不用`,
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/parser"
|
||||
"go/token"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/yetone/magpie/internal/agent"
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
)
|
||||
|
||||
// tuiWords is every word the TUI hands tr or trf, read from its source:
|
||||
// each literal tr and trf are called with, each label hints is (every
|
||||
// second argument), and the tables whose values go through tr where they
|
||||
// are shown. fmts says which of them are formats.
|
||||
func tuiWords(t *testing.T) (all []string, fmts map[string]bool) {
|
||||
t.Helper()
|
||||
files, err := filepath.Glob("*.go")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
fmts = map[string]bool{}
|
||||
seen := map[string]bool{}
|
||||
add := func(s string) {
|
||||
if !seen[s] {
|
||||
seen[s] = true
|
||||
all = append(all, s)
|
||||
}
|
||||
}
|
||||
fset := token.NewFileSet()
|
||||
for _, name := range files {
|
||||
if strings.HasSuffix(name, "_test.go") || name == "i18n.go" {
|
||||
continue
|
||||
}
|
||||
f, err := parser.ParseFile(fset, name, nil, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ast.Inspect(f, func(n ast.Node) bool {
|
||||
call, ok := n.(*ast.CallExpr)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
fn, ok := call.Fun.(*ast.Ident)
|
||||
if !ok {
|
||||
return true
|
||||
}
|
||||
lit := func(e ast.Expr) (string, bool) {
|
||||
b, ok := e.(*ast.BasicLit)
|
||||
if !ok || b.Kind != token.STRING {
|
||||
return "", false
|
||||
}
|
||||
s, err := strconv.Unquote(b.Value)
|
||||
return s, err == nil
|
||||
}
|
||||
switch fn.Name {
|
||||
case "tr", "trf":
|
||||
if len(call.Args) == 0 {
|
||||
return true
|
||||
}
|
||||
if s, ok := lit(call.Args[0]); ok {
|
||||
add(s)
|
||||
if fn.Name == "trf" {
|
||||
fmts[s] = true
|
||||
}
|
||||
}
|
||||
case "hints":
|
||||
for i := 1; i < len(call.Args); i += 2 {
|
||||
if s, ok := lit(call.Args[i]); ok {
|
||||
add(s)
|
||||
}
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
for _, n := range pageNames {
|
||||
add(n)
|
||||
}
|
||||
for _, n := range periodNames {
|
||||
add(n)
|
||||
}
|
||||
for _, r := range sessRanges {
|
||||
add(r.name)
|
||||
}
|
||||
for _, api := range customAPIs {
|
||||
add(api.name)
|
||||
}
|
||||
// sessions' stats tables and chart unit, shown through tr(head) and tr(…[byCost])
|
||||
for _, s := range []string{allModels, allFolders, "models", "folders", "tokens", "cost", ruleHint, provider.TraeRefusedWords} {
|
||||
add(s)
|
||||
}
|
||||
for _, a := range agent.All() {
|
||||
for _, f := range a.Fields {
|
||||
if !keepAsIs[f.Label] {
|
||||
add(f.Label)
|
||||
}
|
||||
}
|
||||
}
|
||||
return all, fmts
|
||||
}
|
||||
|
||||
// keepAsIs are field labels that are names, not words: the same in any
|
||||
// language, so tr gives them back as they are.
|
||||
var keepAsIs = map[string]bool{"magpie": true, "ultracode": true, "harness": true, "opus": true, "sonnet": true, "haiku": true, "fable": true}
|
||||
|
||||
var verbRe = regexp.MustCompile(`%(\[\d+\])?[-+# 0]*\d*(\.\d+)?[a-zA-Z%]`)
|
||||
|
||||
// sample is an argument for each of format's verbs, of the verb's type.
|
||||
func sample(format string) []any {
|
||||
var args []any
|
||||
next := 0
|
||||
for _, m := range verbRe.FindAllStringSubmatch(format, -1) {
|
||||
v := m[0]
|
||||
if v[len(v)-1] == '%' {
|
||||
continue
|
||||
}
|
||||
i := next
|
||||
if m[1] != "" { // %[n]: the nth argument
|
||||
i, _ = strconv.Atoi(strings.Trim(m[1], "[]"))
|
||||
i--
|
||||
}
|
||||
next = i + 1
|
||||
for len(args) <= i {
|
||||
args = append(args, nil)
|
||||
}
|
||||
switch v[len(v)-1] {
|
||||
case 'd':
|
||||
args[i] = 7
|
||||
case 'f':
|
||||
args[i] = 1.5
|
||||
default:
|
||||
args[i] = "x"
|
||||
}
|
||||
}
|
||||
return args
|
||||
}
|
||||
|
||||
// TestEveryWordHasZh fails on a word the TUI shows with no Chinese, so
|
||||
// a new string can't slip in English only, and on a Chinese format whose
|
||||
// verbs don't take the English one's arguments.
|
||||
func TestEveryWordHasZh(t *testing.T) {
|
||||
all, fmts := tuiWords(t)
|
||||
if len(all) < 300 {
|
||||
t.Fatalf("read only %d words from the source", len(all))
|
||||
}
|
||||
for _, s := range all {
|
||||
w, ok := zh[s]
|
||||
if !ok || strings.TrimSpace(w) == "" && strings.TrimSpace(s) != "" {
|
||||
t.Errorf("no zh for %q", s)
|
||||
continue
|
||||
}
|
||||
if !fmts[s] {
|
||||
continue
|
||||
}
|
||||
args := sample(s)
|
||||
if got := fmt.Sprintf(s, args...); strings.Contains(got, "%!") {
|
||||
t.Errorf("English format %q takes its own arguments badly: %s", s, got)
|
||||
}
|
||||
if got := fmt.Sprintf(w, args...); strings.Contains(got, "%!") {
|
||||
t.Errorf("zh %q doesn't take the arguments of %q: %s", w, s, got)
|
||||
}
|
||||
}
|
||||
// a word left behind when its string went away
|
||||
used := map[string]bool{}
|
||||
for _, s := range all {
|
||||
used[s] = true
|
||||
}
|
||||
for k := range zh {
|
||||
if !used[k] {
|
||||
t.Errorf("zh has %q, which the TUI no longer shows", k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestZhDateLayout(t *testing.T) {
|
||||
if got := time.Date(2026, 3, 4, 0, 0, 0, 0, time.UTC).Format(zh["Jan 2"]); got != "3月4日" {
|
||||
t.Fatalf("zh's Jan 2 layout gives %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSpeak(t *testing.T) {
|
||||
for in, want := range map[string]string{"zh": "zh", "zh-TW": "zh", "en": "en", "ja": "en", "de": "en", "": "en"} {
|
||||
if got := speak(in); got != want {
|
||||
t.Errorf("speak(%q) = %q, want %q", in, got, want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestPagesInChinese renders the header and a footer with Chinese picked:
|
||||
// what the user sees, not just the table.
|
||||
func TestPagesInChinese(t *testing.T) {
|
||||
lang = "zh"
|
||||
defer func() { lang = "en" }()
|
||||
if got := trf("%d call%s", 2, plural(2)); got != "2 次调用" {
|
||||
t.Errorf("plural in zh: %q", got)
|
||||
}
|
||||
if got := hints("q", "quit"); !strings.Contains(got, "退出") {
|
||||
t.Errorf("hints in zh: %q", got)
|
||||
}
|
||||
m := model{page: pageProviders, w: 100, h: 30}
|
||||
if got := m.header(); !strings.Contains(got, "供应商") || !strings.Contains(got, "路由") {
|
||||
t.Errorf("header in zh: %q", got)
|
||||
}
|
||||
if got := sessAgo(time.Now().Add(-3*time.Hour), time.Now()); got != "3小时前" {
|
||||
t.Errorf("sessAgo in zh: %q", got)
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package tui
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -62,11 +61,11 @@ func keepGateway(connected bool) string {
|
||||
switch {
|
||||
case err == nil && st.Installed:
|
||||
if err := k.start(); err == nil {
|
||||
return "magpie: the gateway goes on in magpie's service (magpie daemon status)"
|
||||
return tr("magpie: the gateway goes on in magpie's service (magpie daemon status)")
|
||||
}
|
||||
case err == nil && !k.removed():
|
||||
if err := k.install(); err == nil {
|
||||
msg := "magpie: the gateway goes on in magpie's service, which now starts with this system or your login, so agents connected to magpie reach it with magpie tui closed; magpie daemon uninstall removes it"
|
||||
msg := tr("magpie: the gateway goes on in magpie's service, which now starts with this system or your login, so agents connected to magpie reach it with magpie tui closed; magpie daemon uninstall removes it")
|
||||
if l := k.linger(); l != "" {
|
||||
msg += " (" + l + ")"
|
||||
}
|
||||
@@ -75,13 +74,13 @@ func keepGateway(connected bool) string {
|
||||
}
|
||||
pid, log, err := k.background()
|
||||
if err != nil {
|
||||
return gatewayGoneNote() + " (couldn't start magpie serve in the background: " + err.Error() + ")"
|
||||
return gatewayGoneNote() + " " + trf("(couldn't start magpie serve in the background: %s)", err.Error())
|
||||
}
|
||||
msg := fmt.Sprintf("magpie: the gateway goes on in the background (magpie serve, pid %d, log %s) until this system stops", pid, log)
|
||||
msg := trf("magpie: the gateway goes on in the background (magpie serve, pid %d, log %s) until this system stops", pid, log)
|
||||
if wslHere() {
|
||||
msg += "; for it to start with WSL, turn systemd on with [boot] systemd=true in /etc/wsl.conf and run magpie daemon install"
|
||||
msg += tr("; for it to start with WSL, turn systemd on with [boot] systemd=true in /etc/wsl.conf and run magpie daemon install")
|
||||
} else {
|
||||
msg += "; magpie daemon install starts it with the system"
|
||||
msg += tr("; magpie daemon install starts it with the system")
|
||||
}
|
||||
return msg
|
||||
}
|
||||
@@ -92,7 +91,7 @@ func keepGateway(connected bool) string {
|
||||
// which nothing ever starts (#3756): the note says the switch that has the
|
||||
// terminal hand the gateway on instead.
|
||||
func atLoginNote() string {
|
||||
return gatewayGoneNote() + "; magpie opens at login and serves it then. Where no desktop logs in here, `magpie autostart off` has magpie tui hand it on as it quits"
|
||||
return gatewayGoneNote() + tr("; magpie opens at login and serves it then. Where no desktop logs in here, `magpie autostart off` has magpie tui hand it on as it quits")
|
||||
}
|
||||
|
||||
// BackgroundLog is the log of a magpie serve that magpie tui left
|
||||
|
||||
+91
-80
@@ -44,11 +44,11 @@ func (m *model) reloadLibrary() {
|
||||
}
|
||||
m.libView = v
|
||||
m.libAgents = v.Agents
|
||||
ins := libRow{kind: "instructions", name: "shared instructions"}
|
||||
ins := libRow{kind: "instructions", name: tr("shared instructions")}
|
||||
if lines := strings.TrimRight(v.Instructions.Shared, "\n"); strings.TrimSpace(lines) == "" {
|
||||
ins.about = "none yet · e writes them"
|
||||
ins.about = tr("none yet · e writes them")
|
||||
} else {
|
||||
ins.about = fmt.Sprintf("%d line%s", strings.Count(lines, "\n")+1, plural(strings.Count(lines, "\n")+1))
|
||||
ins.about = trf("%d line%s", strings.Count(lines, "\n")+1, plural(strings.Count(lines, "\n")+1))
|
||||
}
|
||||
for _, a := range v.Instructions.Agents {
|
||||
if a.On {
|
||||
@@ -65,20 +65,20 @@ func (m *model) reloadLibrary() {
|
||||
what = strings.TrimSpace(s.Command + " " + strings.Join(s.Args, " "))
|
||||
}
|
||||
if s.Local {
|
||||
what = "not synced · " + what
|
||||
what = tr("not synced") + " · " + what
|
||||
}
|
||||
m.lib = append(m.lib, libRow{kind: "mcp", name: s.Name, about: what, on: s.Agents, bad: len(s.Problems)})
|
||||
}
|
||||
for _, s := range v.Skills {
|
||||
r := libRow{kind: "skill", name: s.Name, about: s.Description, on: s.Agents, bad: len(s.Problems)}
|
||||
if s.Missing {
|
||||
r.about, r.bad = "its folder is gone", r.bad+1
|
||||
r.about, r.bad = tr("its folder is gone"), r.bad+1
|
||||
} else if s.Gone != "" {
|
||||
r.about, r.bad = "removed from "+s.Source+" · d takes it out", r.bad+1
|
||||
r.about, r.bad = trf("removed from %s · d takes it out", s.Source), r.bad+1
|
||||
}
|
||||
if s.OffHere {
|
||||
// ticked agents are other computers' too; none gets it here
|
||||
r.about = "off on this computer · magpie library skill on-here " + s.Name
|
||||
r.about = trf("off on this computer · magpie library skill on-here %s", s.Name)
|
||||
}
|
||||
m.lib = append(m.lib, r)
|
||||
}
|
||||
@@ -92,9 +92,9 @@ func (m *model) reloadLibrary() {
|
||||
r := libRow{kind: "rtk", name: "RTK"}
|
||||
switch {
|
||||
case rv.Path == "":
|
||||
r.about = "not installed · " + rv.URL
|
||||
r.about = tr("not installed") + " · " + rv.URL
|
||||
case rv.Gain != nil:
|
||||
r.about = fmt.Sprintf("%s · %s tokens saved", rv.Version, fmtTokens(int(rv.Gain.Saved)))
|
||||
r.about = trf("%s · %s tokens saved", rv.Version, fmtTokens(int(rv.Gain.Saved)))
|
||||
default:
|
||||
r.about = rv.Version
|
||||
}
|
||||
@@ -139,8 +139,8 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.openLibAdd()
|
||||
return m, nil
|
||||
case "s":
|
||||
m.flash, m.flashOK = "writing the library into the agents…", true
|
||||
return m, libCmd(library.Sync, "synced")
|
||||
m.flash, m.flashOK = tr("writing the library into the agents…"), true
|
||||
return m, libCmd(library.Sync, tr("synced"))
|
||||
}
|
||||
if n == 0 {
|
||||
return m, nil
|
||||
@@ -152,9 +152,9 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
case "instructions", "mcp", "skill", "rtk":
|
||||
m.openLibAgents(r)
|
||||
case "found-mcp", "found-skill":
|
||||
m.flash, m.flashOK = "i brings "+r.name+" into the library, for magpie to give it to other agents too", true
|
||||
m.flash, m.flashOK = trf("i brings %s into the library, for magpie to give it to other agents too", r.name), true
|
||||
if !r.own {
|
||||
m.flash += "; d takes it out of every agent that has it"
|
||||
m.flash += "; " + tr("d takes it out of every agent that has it")
|
||||
}
|
||||
}
|
||||
case "e":
|
||||
@@ -168,19 +168,19 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if r.kind != "skill" {
|
||||
return m, nil
|
||||
}
|
||||
m.flash, m.flashOK = "fetching "+r.name+" from GitHub again…", true
|
||||
m.flash, m.flashOK = trf("fetching %s from GitHub again…", r.name), true
|
||||
return m, libCmd(func() (*library.Result, error) {
|
||||
res, err := library.UpdateSkill(r.name, false)
|
||||
var gone *library.GoneError
|
||||
if errors.As(err, &gone) {
|
||||
// removed from its source: kept till the user takes it out
|
||||
err = fmt.Errorf("%w · d takes it out", err)
|
||||
err = fmt.Errorf("%w · %s", err, tr("d takes it out"))
|
||||
}
|
||||
return res, err
|
||||
}, "updated "+r.name)
|
||||
}, trf("updated %s", r.name))
|
||||
case "i":
|
||||
if r.own {
|
||||
m.flash, m.flashOK = r.name+" is put there by the agent's app itself, each time it starts: it stays as it is", false
|
||||
m.flash, m.flashOK = trf("%s is put there by the agent's app itself, each time it starts: it stays as it is", r.name), false
|
||||
return m, nil
|
||||
}
|
||||
var do func(string) (*library.Result, error)
|
||||
@@ -192,7 +192,7 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
default:
|
||||
return m, nil
|
||||
}
|
||||
return m, libCmd(func() (*library.Result, error) { return do(r.name) }, "brought "+r.name+" into the library")
|
||||
return m, libCmd(func() (*library.Result, error) { return do(r.name) }, trf("brought %s into the library", r.name))
|
||||
case "d":
|
||||
var do func(string) (*library.Result, error)
|
||||
switch r.kind {
|
||||
@@ -204,7 +204,7 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
do = library.RemoveFoundSkill
|
||||
case "found-mcp":
|
||||
if r.own {
|
||||
m.flash, m.flashOK = r.name+" is put there by the agent's app itself, each time it starts: it stays as it is", false
|
||||
m.flash, m.flashOK = trf("%s is put there by the agent's app itself, each time it starts: it stays as it is", r.name), false
|
||||
return m, nil
|
||||
}
|
||||
do = library.RemoveFoundServer
|
||||
@@ -213,17 +213,17 @@ func (m model) updateLibrary(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
if m.confirm != "library/"+r.kind+"/"+r.name {
|
||||
m.confirm = "library/" + r.kind + "/" + r.name
|
||||
m.flash, m.flashOK = "press d again to take "+r.name+" out of the library and every agent", false
|
||||
m.flash, m.flashOK = trf("press d again to take %s out of the library and every agent", r.name), false
|
||||
switch r.kind {
|
||||
case "found-skill":
|
||||
m.flash = "press d again to take " + r.name + " out of every agent that has it, kept with the backups"
|
||||
m.flash = trf("press d again to take %s out of every agent that has it, kept with the backups", r.name)
|
||||
case "found-mcp":
|
||||
m.flash = "press d again to take " + r.name + " out of every agent that has it, their files kept with the backups"
|
||||
m.flash = trf("press d again to take %s out of every agent that has it, their files kept with the backups", r.name)
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
m.confirm = ""
|
||||
return m, libCmd(func() (*library.Result, error) { return do(r.name) }, "removed "+r.name)
|
||||
return m, libCmd(func() (*library.Result, error) { return do(r.name) }, trf("removed %s", r.name))
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -244,20 +244,20 @@ func libCmd(do func() (*library.Result, error), done string) tea.Cmd {
|
||||
func libSaid(res *library.Result, done string) (string, bool) {
|
||||
// an install of skills the library had already added none
|
||||
if len(res.Installed) == 0 && len(res.Had) > 0 {
|
||||
done = strings.Join(res.Had, ", ") + " in the library already"
|
||||
done = trf("%s in the library already", strings.Join(res.Had, ", "))
|
||||
}
|
||||
// a skill from a folder, linked to the one installed (skill_link.go)
|
||||
if len(res.Installed) == 0 && len(res.Linked) > 0 {
|
||||
done = strings.Join(res.Linked, ", ") + " updates from GitHub now"
|
||||
done = trf("%s updates from GitHub now", strings.Join(res.Linked, ", "))
|
||||
}
|
||||
if len(res.LinkedKept) > 0 {
|
||||
done += " · files of their own kept with the backups: " + strings.Join(res.LinkedKept, ", ")
|
||||
done += " · " + trf("files of their own kept with the backups: %s", strings.Join(res.LinkedKept, ", "))
|
||||
}
|
||||
for _, p := range res.Skipped {
|
||||
done += " · " + strings.TrimPrefix(p.What, "skill:") + " skipped: " + p.Error
|
||||
done += " · " + trf("%s skipped: %s", strings.TrimPrefix(p.What, "skill:"), p.Error)
|
||||
}
|
||||
if len(res.Changed) > 0 {
|
||||
done += " · written into " + strings.Join(res.Changed, ", ")
|
||||
done += " · " + trf("written into %s", strings.Join(res.Changed, ", "))
|
||||
}
|
||||
for _, p := range res.Problems {
|
||||
done += " · " + p.Agent + ": " + p.Error
|
||||
@@ -270,9 +270,9 @@ func libSaid(res *library.Result, done string) (string, bool) {
|
||||
func (m model) libOptions(r libRow) []agent.Option {
|
||||
var out []agent.Option
|
||||
add := func(id, name string) {
|
||||
note := "○ off"
|
||||
note := "○ " + tr("off")
|
||||
if slices.Contains(r.on, id) {
|
||||
note = "● on"
|
||||
note = "● " + tr("on")
|
||||
}
|
||||
out = append(out, agent.Option{Value: id, Note: note + " " + name})
|
||||
}
|
||||
@@ -294,12 +294,12 @@ func (m model) libOptions(r libRow) []agent.Option {
|
||||
// openLibAgents lists the agents a row can go to; enter gives it to one or
|
||||
// takes it away, and the list stays open.
|
||||
func (m *model) openLibAgents(r libRow) {
|
||||
crumbs := []string{"library", r.name, "agents"}
|
||||
crumbs := []string{tr("library"), r.name, tr("agents")}
|
||||
m.pk = picker{
|
||||
crumbs: crumbs,
|
||||
input: newInput("filter agents"),
|
||||
input: newInput(tr("filter agents")),
|
||||
items: m.libOptions(r),
|
||||
empty: "no agent here has a place for it",
|
||||
empty: tr("no agent here has a place for it"),
|
||||
toggle: func(id string) ([]agent.Option, string, bool) {
|
||||
on := !slices.Contains(r.on, id)
|
||||
var (
|
||||
@@ -317,9 +317,9 @@ func (m *model) openLibAgents(r libRow) {
|
||||
r.on = append(r.on, a.ID)
|
||||
}
|
||||
}
|
||||
text = "RTK " + map[bool]string{true: "on", false: "off"}[on] + " for " + m.libName(id)
|
||||
text = trf("RTK %s for %s", map[bool]string{true: tr("on"), false: tr("off")}[on], m.libName(id))
|
||||
if len(v.Restart) > 0 {
|
||||
text += " · restart " + strings.Join(v.Restart, ", ") + " for it to take effect"
|
||||
text += " · " + trf("restart %s for it to take effect", strings.Join(v.Restart, ", "))
|
||||
}
|
||||
} else {
|
||||
agents := slices.Clone(r.on)
|
||||
@@ -344,11 +344,11 @@ func (m *model) openLibAgents(r libRow) {
|
||||
return nil, err.Error(), false
|
||||
}
|
||||
r.on = agents
|
||||
verb := "given to "
|
||||
said := trf("%s given to %s", r.name, m.libName(id))
|
||||
if !on {
|
||||
verb = "taken from "
|
||||
said = trf("%s taken from %s", r.name, m.libName(id))
|
||||
}
|
||||
text, ok = libSaid(&library.Result{Problems: res.Problems}, r.name+" "+verb+m.libName(id))
|
||||
text, ok = libSaid(&library.Result{Problems: res.Problems}, said)
|
||||
}
|
||||
return m.libOptions(r), text, ok
|
||||
},
|
||||
@@ -361,25 +361,25 @@ func (m *model) openLibAgents(r libRow) {
|
||||
// openLibAdd picks what to add: an MCP server, or skills.
|
||||
func (m *model) openLibAdd() {
|
||||
m.pk = picker{
|
||||
crumbs: []string{"library", "add"},
|
||||
input: newInput("filter"),
|
||||
crumbs: []string{tr("library"), tr("add")},
|
||||
input: newInput(tr("filter")),
|
||||
items: []agent.Option{
|
||||
{Value: "mcp server", Note: "a URL, or a command it runs"},
|
||||
{Value: "skills", Note: "from GitHub, GitLab or any git repository, or a folder on this machine"},
|
||||
{Value: tr("mcp server"), Note: tr("a URL, or a command it runs")},
|
||||
{Value: tr("skills"), Note: tr("from GitHub, GitLab or any git repository, or a folder on this machine")},
|
||||
},
|
||||
onPick: func(v string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if v == "skills" {
|
||||
in := newInput("owner/repo, a GitHub or GitLab link, a git address (git@host:group/repo.git), or a folder's full path")
|
||||
if v == tr("skills") {
|
||||
in := newInput(tr("owner/repo, a GitHub or GitLab link, a git address (git@host:group/repo.git), or a folder's full path"))
|
||||
in.CharLimit = 400
|
||||
return askMsg{ask{crumbs: []string{"library", "add", "skills"}, input: in,
|
||||
hint: "magpie looks there for skills, then you pick one",
|
||||
return askMsg{ask{crumbs: []string{tr("library"), tr("add"), tr("skills")}, input: in,
|
||||
hint: tr("magpie looks there for skills, then you pick one"),
|
||||
onEnter: probeCmd}}
|
||||
}
|
||||
in := newInput("<name> <url | command args…>")
|
||||
in := newInput(tr("<name> <url | command args…>"))
|
||||
in.CharLimit = 400
|
||||
return askMsg{ask{crumbs: []string{"library", "add", "mcp server"}, input: in,
|
||||
hint: "e.g. context7 https://mcp.context7.com/mcp · fs npx -y @modelcontextprotocol/server-filesystem ~/code\nthen ↵ on it gives it to agents",
|
||||
return askMsg{ask{crumbs: []string{tr("library"), tr("add"), tr("mcp server")}, input: in,
|
||||
hint: trf("e.g. %s", "context7 https://mcp.context7.com/mcp · fs npx -y @modelcontextprotocol/server-filesystem ~/code") + "\n" + tr("then ↵ on it gives it to agents"),
|
||||
onEnter: func(line string) tea.Cmd { return saveServer(nil, line) }}}
|
||||
}
|
||||
},
|
||||
@@ -406,12 +406,12 @@ func (m *model) openServer(name string) {
|
||||
if old.Command != "" {
|
||||
line = strings.Join(append([]string{old.Name, old.Command}, old.Args...), " ")
|
||||
}
|
||||
in := newInput("<name> <url | command args…>")
|
||||
in := newInput(tr("<name> <url | command args…>"))
|
||||
in.CharLimit = 400
|
||||
in.SetValue(line)
|
||||
in.CursorEnd()
|
||||
m.openAsk(ask{crumbs: []string{"library", name, "edit"}, input: in,
|
||||
hint: "its env, headers and agents stay as they are",
|
||||
m.openAsk(ask{crumbs: []string{tr("library"), name, tr("edit")}, input: in,
|
||||
hint: tr("its env, headers and agents stay as they are"),
|
||||
onEnter: func(line string) tea.Cmd { return saveServer(old, line) }})
|
||||
}
|
||||
|
||||
@@ -421,15 +421,15 @@ func saveServer(old *library.Server, line string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
words := strings.Fields(line)
|
||||
if len(words) < 2 {
|
||||
return flashMsg{text: "a name, then a URL or a command"}
|
||||
return flashMsg{text: tr("a name, then a URL or a command")}
|
||||
}
|
||||
s, err := library.ServerOf(words[0], words[1:])
|
||||
if err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
was, done := "", "added "+s.Name+" · ↵ on it gives it to agents"
|
||||
was, done := "", trf("added %s · ↵ on it gives it to agents", s.Name)
|
||||
if old != nil {
|
||||
was, done = old.Name, "saved "+s.Name
|
||||
was, done = old.Name, trf("saved %s", s.Name)
|
||||
// and its OAuth app and startup timeout, which only the GUI edits
|
||||
// and whether it is kept to this computer, and out of the hub,
|
||||
// and the user's note on it
|
||||
@@ -464,16 +464,16 @@ func (m *model) openProbe(p *library.Probe) {
|
||||
note := c.Description
|
||||
switch {
|
||||
case c.Have && c.As != "":
|
||||
note = "in the library as " + c.As + " · " + note
|
||||
note = trf("in the library as %s", c.As) + " · " + note
|
||||
case c.Have:
|
||||
note = "in the library already · " + note
|
||||
note = tr("in the library already") + " · " + note
|
||||
case c.Links:
|
||||
// the library's by its name came from a folder: this one
|
||||
// takes its place, and it updates from GitHub from then on
|
||||
note = "links the library's to GitHub · " + note
|
||||
note = tr("links the library's to GitHub") + " · " + note
|
||||
case c.As != "":
|
||||
// another skill from elsewhere has its name
|
||||
note = "adds as " + c.As + " · " + note
|
||||
note = trf("adds as %s", c.As) + " · " + note
|
||||
}
|
||||
v := c.Path
|
||||
if v == "" {
|
||||
@@ -482,17 +482,17 @@ func (m *model) openProbe(p *library.Probe) {
|
||||
items = append(items, agent.Option{Value: v, Note: c.Name + " " + trunc(note, 80)})
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: []string{"library", "add", "skills", p.Source},
|
||||
input: newInput("filter skills"),
|
||||
crumbs: []string{tr("library"), tr("add"), tr("skills"), p.Source},
|
||||
input: newInput(tr("filter skills")),
|
||||
items: items,
|
||||
empty: "no skills there: a skill is a folder with a SKILL.md",
|
||||
empty: tr("no skills there: a skill is a folder with a SKILL.md"),
|
||||
onPick: func(path string) tea.Cmd {
|
||||
if path == "." {
|
||||
path = ""
|
||||
}
|
||||
return libCmd(func() (*library.Result, error) {
|
||||
return library.InstallSkills(p.Source, []string{path}, []string{})
|
||||
}, "added the skill · ↵ on it gives it to agents")
|
||||
}, tr("added the skill · ↵ on it gives it to agents"))
|
||||
},
|
||||
}
|
||||
m.pk.refilter()
|
||||
@@ -508,7 +508,7 @@ func (m *model) openProbe(p *library.Probe) {
|
||||
left = append(left, fmt.Sprintf("%s (%d MB)", name, l.Size>>20))
|
||||
}
|
||||
if len(left) > 0 {
|
||||
m.flash = "too big to install, over 200 MB a skill: " + strings.Join(left, ", ")
|
||||
m.flash = trf("too big to install, over 200 MB a skill: %s", strings.Join(left, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -554,7 +554,7 @@ func editInstructions() tea.Cmd {
|
||||
return editedMsg{err: err}
|
||||
}
|
||||
if string(b) == v.Shared {
|
||||
return flashMsg{text: "the instructions are as they were", ok: true}
|
||||
return flashMsg{text: tr("the instructions are as they were"), ok: true}
|
||||
}
|
||||
return editedMsg{text: string(b)}
|
||||
})
|
||||
@@ -563,7 +563,7 @@ func editInstructions() tea.Cmd {
|
||||
func saveInstructions(text string) tea.Cmd {
|
||||
return libCmd(func() (*library.Result, error) {
|
||||
return library.SaveInstructions(library.InstructionsChange{Shared: &text})
|
||||
}, "instructions saved")
|
||||
}, tr("instructions saved"))
|
||||
}
|
||||
|
||||
func (m model) viewLibrary() string {
|
||||
@@ -576,16 +576,16 @@ func (m model) viewLibrary() string {
|
||||
}
|
||||
nameW := 0
|
||||
for _, r := range m.lib {
|
||||
nameW = max(nameW, len([]rune(r.name)))
|
||||
nameW = max(nameW, lipgloss.Width(r.name))
|
||||
}
|
||||
nameW = min(nameW, 32)
|
||||
heads := map[string]string{
|
||||
"instructions": "instructions · what every agent reads before a conversation",
|
||||
"mcp": "mcp servers · a adds one, e changes it",
|
||||
"skill": "skills · a adds some from GitHub or a folder, u fetches one from GitHub again",
|
||||
"found-mcp": "mcp servers in your agents, not in the library",
|
||||
"found-skill": "skills in your agents, not in the library",
|
||||
"rtk": "rtk · its hook in each agent, by RTK's own installer",
|
||||
"instructions": tr("instructions · what every agent reads before a conversation"),
|
||||
"mcp": tr("mcp servers · a adds one, e changes it"),
|
||||
"skill": tr("skills · a adds some from GitHub or a folder, u fetches one from GitHub again"),
|
||||
"found-mcp": tr("mcp servers in your agents, not in the library"),
|
||||
"found-skill": tr("skills in your agents, not in the library"),
|
||||
"rtk": tr("rtk · its hook in each agent, by RTK's own installer"),
|
||||
}
|
||||
// the rows around the cursor, as many as fit
|
||||
visible := max(4, m.h-6)
|
||||
@@ -632,10 +632,10 @@ func (m model) viewLibrary() string {
|
||||
on := sMuted.Render(strings.Join(agents, ", "))
|
||||
switch {
|
||||
case r.own:
|
||||
on = sFaint.Render(strings.Join(agents, ", ") + "'s own")
|
||||
on = sFaint.Render(trf("%s's own", strings.Join(agents, ", ")))
|
||||
case len(agents) == 0 && strings.HasPrefix(r.kind, "found-"):
|
||||
case len(agents) == 0:
|
||||
on = sFaint.Render("no agent")
|
||||
on = sFaint.Render(tr("no agent"))
|
||||
}
|
||||
line := pad + marker + name + " " + on
|
||||
if r.bad > 0 {
|
||||
@@ -649,15 +649,26 @@ func (m model) viewLibrary() string {
|
||||
b.WriteString(line + "\n")
|
||||
lines++
|
||||
}
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render("kept in "+tilde(m.libView.Dir)))
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render(trf("kept in %s", tilde(m.libView.Dir))))
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// trunc cuts s to n runes, with an ellipsis.
|
||||
// trunc cuts s to n columns, with an ellipsis: a Chinese character takes
|
||||
// two.
|
||||
func trunc(s string, n int) string {
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if r := []rune(s); len(r) > n {
|
||||
return string(r[:max(1, n-1)]) + "…"
|
||||
if lipgloss.Width(s) <= n {
|
||||
return s
|
||||
}
|
||||
return s
|
||||
var b strings.Builder
|
||||
w := 0
|
||||
for _, r := range s {
|
||||
rw := lipgloss.Width(string(r))
|
||||
if b.Len() > 0 && w+rw > n-1 {
|
||||
break
|
||||
}
|
||||
b.WriteRune(r)
|
||||
w += rw
|
||||
}
|
||||
return b.String() + "…"
|
||||
}
|
||||
|
||||
+148
-138
@@ -81,7 +81,7 @@ func balancesCmd(ps []provider.Provider) tea.Cmd {
|
||||
}
|
||||
v := amount
|
||||
if err != nil {
|
||||
v = "balance: " + err.Error()
|
||||
v = trf("balance: %s", err.Error())
|
||||
if r := []rune(v); len(r) > 60 {
|
||||
v = string(r[:60]) + "…"
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (m model) updateProviders(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.openPresets()
|
||||
return m, nil
|
||||
case "b":
|
||||
m.flash, m.flashOK = "asking the vendors for balances…", true
|
||||
m.flash, m.flashOK = tr("asking the vendors for balances…"), true
|
||||
return m, balancesCmd(m.provs)
|
||||
}
|
||||
if n == 0 {
|
||||
@@ -129,43 +129,43 @@ func (m model) updateProviders(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.openProviderModels(p.ID)
|
||||
case "e":
|
||||
if p.Account != nil {
|
||||
m.flash, m.flashOK = p.Name+" is a signed-in account: its key is the agent's sign-in", false
|
||||
m.flash, m.flashOK = trf("%s is a signed-in account: its key is the agent's sign-in", p.Name), false
|
||||
return m, nil
|
||||
}
|
||||
if p.IsVertex() {
|
||||
// its token is minted from the user's Google credentials
|
||||
m.flash, m.flashOK = p.Name+" takes no key · magpie provider set "+p.ID+" credentials=… impersonate=… changes its Google credentials", false
|
||||
m.flash, m.flashOK = trf("%s takes no key · magpie provider set %s credentials=… impersonate=… changes its Google credentials", p.Name, p.ID), false
|
||||
return m, nil
|
||||
}
|
||||
in := newInput("the API key")
|
||||
in := newInput(tr("the API key"))
|
||||
in.EchoMode = textinput.EchoPassword
|
||||
in.EchoCharacter = '•'
|
||||
m.openAsk(ask{crumbs: []string{"providers", p.Name, "key"}, input: in,
|
||||
hint: "now " + dash(provider.Mask(p.Key)) + " · the key is kept in magpie's providers file",
|
||||
m.openAsk(ask{crumbs: []string{tr("providers"), p.Name, tr("key")}, input: in,
|
||||
hint: trf("now %s · the key is kept in magpie's providers file", dash(provider.Mask(p.Key))),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveProvider(p.ID, func(p *provider.Provider) { p.Key = v; provider.ForgetBalances() }, p.Name+" key "+provider.Mask(v))
|
||||
return saveProvider(p.ID, func(p *provider.Provider) { p.Key = v; provider.ForgetBalances() }, trf("%s key %s", p.Name, provider.Mask(v)))
|
||||
}})
|
||||
case "w":
|
||||
if p.IsVertex() {
|
||||
m.flash, m.flashOK = p.Name+" is asked at your Google Cloud project · magpie provider set "+p.ID+" project=… location=… changes it", false
|
||||
m.flash, m.flashOK = trf("%s is asked at your Google Cloud project · magpie provider set %s project=… location=… changes it", p.Name, p.ID), false
|
||||
return m, nil
|
||||
}
|
||||
pr := provider.Preset(p.Preset)
|
||||
if pr != nil && pr.Kind == provider.KindLocal {
|
||||
id, name := p.ID, p.Name
|
||||
now := provider.AddressOf(p.Chat, p.Responses, p.Anthropic)
|
||||
m.openAsk(localAddressAsk(*pr, []string{"providers", name, "address"}, now, func(v string) tea.Cmd {
|
||||
m.openAsk(localAddressAsk(*pr, []string{tr("providers"), name, tr("address")}, now, func(v string) tea.Cmd {
|
||||
q := p
|
||||
_ = q.AtAddress(v)
|
||||
// the address it opened with: URLs set apart (an Anthropic
|
||||
// URL on another host) aren't moved onto the first one's
|
||||
if at := provider.AddressOf(q.Chat, q.Responses, q.Anthropic); v == "" || at == now {
|
||||
return func() tea.Msg { return flashMsg{text: name + " address unchanged", ok: true} }
|
||||
return func() tea.Msg { return flashMsg{text: trf("%s address unchanged", name), ok: true} }
|
||||
}
|
||||
return saveProvider(id, func(p *provider.Provider) {
|
||||
_ = p.AtAddress(v)
|
||||
provider.ForgetBalances()
|
||||
}, name+" address "+provider.AddressOf(q.Chat, q.Responses, q.Anthropic))
|
||||
}, trf("%s address %s", name, provider.AddressOf(q.Chat, q.Responses, q.Anthropic)))
|
||||
}))
|
||||
return m, nil
|
||||
}
|
||||
@@ -177,7 +177,7 @@ func (m model) updateProviders(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
}
|
||||
if pr == nil || pr.Endpoint == "" {
|
||||
m.flash, m.flashOK = p.Name+" is asked at its vendor's address · magpie provider set "+p.ID+" url=… changes a custom one's", false
|
||||
m.flash, m.flashOK = trf("%s is asked at its vendor's address · magpie provider set %s url=… changes a custom one's", p.Name, p.ID), false
|
||||
return m, nil
|
||||
}
|
||||
now := p.Chat
|
||||
@@ -188,54 +188,54 @@ func (m model) updateProviders(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
now = p.Anthropic // the address as typed, without /v1
|
||||
}
|
||||
id, name := p.ID, p.Name
|
||||
m.openAsk(endpointAsk(*pr, []string{"providers", name, "address"}, now, func(v string) tea.Cmd {
|
||||
m.openAsk(endpointAsk(*pr, []string{tr("providers"), name, tr("address")}, now, func(v string) tea.Cmd {
|
||||
return saveProvider(id, func(p *provider.Provider) {
|
||||
p.Chat, p.Responses = v, v
|
||||
if p.IsRemoteMagpie() {
|
||||
p.Anthropic = "" // put again from the address typed
|
||||
}
|
||||
provider.ForgetBalances()
|
||||
}, name+" address "+v)
|
||||
}, trf("%s address %s", name, v))
|
||||
}))
|
||||
case "f":
|
||||
in := newInput("a tag, e.g. relay")
|
||||
in := newInput(tr("a tag, e.g. relay"))
|
||||
in.SetValue(p.Family)
|
||||
m.openAsk(ask{crumbs: []string{"providers", p.Name, "family"}, input: in, empty: true,
|
||||
hint: "agents can be shown only some families: magpie visible <agent> <family>",
|
||||
m.openAsk(ask{crumbs: []string{tr("providers"), p.Name, tr("family")}, input: in, empty: true,
|
||||
hint: tr("agents can be shown only some families: magpie visible <agent> <family>"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveProvider(p.ID, func(p *provider.Provider) { p.Family = v }, p.Name+" family "+dash(v))
|
||||
return saveProvider(p.ID, func(p *provider.Provider) { p.Family = v }, trf("%s family %s", p.Name, dash(v)))
|
||||
}})
|
||||
case "u":
|
||||
on := !p.Unlisted
|
||||
what := "its models are listed"
|
||||
what := tr("its models are listed")
|
||||
if on {
|
||||
what = "serves only through routing groups"
|
||||
what = tr("serves only through routing groups")
|
||||
}
|
||||
return m, saveProvider(p.ID, func(p *provider.Provider) { p.Unlisted = on }, p.Name+" "+what)
|
||||
case "o":
|
||||
off := !p.Off
|
||||
what := "switched on"
|
||||
what := tr("switched on")
|
||||
if off {
|
||||
what = "switched off: agents are given none of its models"
|
||||
what = tr("switched off: agents are given none of its models")
|
||||
}
|
||||
id := p.ID
|
||||
return m, reseatCmd(func() error { return provider.SetOff(id, off) }, p.Name+" "+what)
|
||||
case "t":
|
||||
m.flash, m.flashOK = "testing "+p.Name+"…", true
|
||||
m.flash, m.flashOK = trf("testing %s…", p.Name), true
|
||||
return m, testCmd(p)
|
||||
case "m":
|
||||
// the vendor's list asked again, as the app editor's Fetch models does
|
||||
m.flash, m.flashOK = "asking "+p.Name+" for its models…", true
|
||||
m.flash, m.flashOK = trf("asking %s for its models…", p.Name), true
|
||||
return m, refetchCmd(p.ID)
|
||||
case "d":
|
||||
if m.confirm != "provider/"+p.ID {
|
||||
m.confirm = "provider/" + p.ID
|
||||
m.flash, m.flashOK = "press d again to remove "+p.Name, false
|
||||
m.flash, m.flashOK = trf("press d again to remove %s", p.Name), false
|
||||
return m, nil
|
||||
}
|
||||
m.confirm = ""
|
||||
id := p.ID
|
||||
return m, reseatCmd(func() error { return provider.Delete(id) }, "removed "+p.Name)
|
||||
return m, reseatCmd(func() error { return provider.Delete(id) }, trf("removed %s", p.Name))
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -253,7 +253,7 @@ func reseatCmd(change func() error, done string) tea.Cmd {
|
||||
done += "; " + mv.String()
|
||||
continue
|
||||
}
|
||||
done += "; moved " + mv.String()
|
||||
done += "; " + trf("moved %s", mv.String())
|
||||
}
|
||||
return flashMsg{text: done, ok: true}
|
||||
}
|
||||
@@ -285,7 +285,7 @@ func refetchCmd(id string) tea.Cmd {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
if p.IsPlugin() {
|
||||
return flashMsg{text: p.Name + "'s models are what its plugin lists"}
|
||||
return flashMsg{text: trf("%s's models are what its plugin lists", p.Name)}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancel()
|
||||
@@ -295,7 +295,7 @@ func refetchCmd(id string) tea.Cmd {
|
||||
}
|
||||
text := p.Name + ": " + modelsNote(id, len(ms))
|
||||
if len(dropped) > 0 {
|
||||
text += " · gone from its list, so no longer picked: " + strings.Join(dropped, ", ")
|
||||
text += " · " + trf("gone from its list, so no longer picked: %s", strings.Join(dropped, ", "))
|
||||
}
|
||||
return flashMsg{text: text, ok: len(ms) > 0}
|
||||
}
|
||||
@@ -304,9 +304,9 @@ func refetchCmd(id string) tea.Cmd {
|
||||
// modelsNote says how many models the vendor's list had and how many of
|
||||
// them agents are offered.
|
||||
func modelsNote(id string, fetched int) string {
|
||||
text := fmt.Sprintf("%d models from its list", fetched)
|
||||
text := trf("%d models from its list", fetched)
|
||||
if p, err := provider.Find(id); err == nil {
|
||||
text += fmt.Sprintf(" · %d for agents (↵ picks)", len(p.Exposed()))
|
||||
text += " · " + trf("%d for agents (↵ picks)", len(p.Exposed()))
|
||||
}
|
||||
return text
|
||||
}
|
||||
@@ -318,7 +318,7 @@ func fetchNote(err error) string {
|
||||
if r := []rune(e); len(r) > 140 {
|
||||
e = string(r[:140]) + "…"
|
||||
}
|
||||
return "no model list · " + strings.TrimPrefix(e, "no model list: ") + " · m asks again"
|
||||
return trf("no model list · %s · m asks again", strings.TrimPrefix(e, "no model list: "))
|
||||
}
|
||||
|
||||
func testCmd(p provider.Provider) tea.Cmd {
|
||||
@@ -343,7 +343,7 @@ func testCmd(p provider.Provider) tea.Cmd {
|
||||
parts = append(parts, fmt.Sprintf("%s ✗ %s", r.Protocol, e))
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return flashMsg{text: p.Name + ": nothing to test"}
|
||||
return flashMsg{text: p.Name + ": " + tr("nothing to test")}
|
||||
}
|
||||
return flashMsg{text: p.Name + ": " + strings.Join(parts, " · "), ok: ok}
|
||||
}
|
||||
@@ -367,9 +367,9 @@ func modelOptions(id string) []agent.Option {
|
||||
return
|
||||
}
|
||||
seen[id] = true
|
||||
note := "○ off"
|
||||
note := "○ " + tr("off")
|
||||
if on[id] {
|
||||
note = "● on"
|
||||
note = "● " + tr("on")
|
||||
}
|
||||
if n, ok := names[id]; ok {
|
||||
name = n // the user's (magpie model name)
|
||||
@@ -393,11 +393,11 @@ func modelOptions(id string) []agent.Option {
|
||||
func (m *model) openProviderModels(id string) {
|
||||
p := m.provs[m.prow]
|
||||
m.pk = picker{
|
||||
crumbs: []string{"providers", p.Name, "models"},
|
||||
input: newInput("filter models"),
|
||||
crumbs: []string{tr("providers"), p.Name, tr("models")},
|
||||
input: newInput(tr("filter models")),
|
||||
items: modelOptions(id),
|
||||
relist: func() []agent.Option { return modelOptions(id) },
|
||||
empty: "no models known yet · ctrl+r asks the vendor for them",
|
||||
empty: tr("no models known yet · ctrl+r asks the vendor for them"),
|
||||
// the list asked again from here, where its models are looked at
|
||||
// (#2113), as m does on the providers list
|
||||
refetch: func() tea.Cmd { return refetchCmd(id) },
|
||||
@@ -415,7 +415,7 @@ func (m *model) openProviderModels(id string) {
|
||||
verb := "on"
|
||||
if i := slices.Index(ids, model); i >= 0 {
|
||||
if len(ids) == 1 {
|
||||
return nil, "one model has to stay on", false
|
||||
return nil, tr("one model has to stay on"), false
|
||||
}
|
||||
ids = slices.Delete(slices.Clone(ids), i, i+1)
|
||||
verb = "off"
|
||||
@@ -430,9 +430,9 @@ func (m *model) openProviderModels(id string) {
|
||||
if !slices.ContainsFunc(items, func(o agent.Option) bool { return o.Value == model }) {
|
||||
// a vendor whose list wasn't fetched knows only those on:
|
||||
// the one just turned off stays to be turned on again
|
||||
items = append(items, agent.Option{Value: model, Note: "○ off"})
|
||||
items = append(items, agent.Option{Value: model, Note: "○ " + tr("off")})
|
||||
}
|
||||
return items, model + " " + verb, true
|
||||
return items, model + " " + tr(verb), true
|
||||
},
|
||||
}
|
||||
m.pk.refilter()
|
||||
@@ -444,7 +444,17 @@ func (m *model) openProviderModels(id string) {
|
||||
// on Discord didn't find it there).
|
||||
func kindNote(k provider.Kind) string {
|
||||
if k == provider.KindRemote {
|
||||
return "another computer's magpie, shared on its network"
|
||||
return tr("another computer's magpie, shared on its network")
|
||||
}
|
||||
switch k {
|
||||
case provider.KindVendor:
|
||||
return tr("vendor")
|
||||
case provider.KindRelay:
|
||||
return tr("relay")
|
||||
case provider.KindLocal:
|
||||
return tr("local")
|
||||
case provider.KindPartner:
|
||||
return tr("partner")
|
||||
}
|
||||
return string(k)
|
||||
}
|
||||
@@ -455,7 +465,7 @@ func (m *model) openPresets() {
|
||||
var items []agent.Option
|
||||
var shown []string
|
||||
for _, d := range provider.Partners() {
|
||||
items = append(items, agent.Option{Value: d.ID, Note: d.Name + " · partner (sponsor)"})
|
||||
items = append(items, agent.Option{Value: d.ID, Note: d.Name + " · " + tr("partner (sponsor)")})
|
||||
shown = append(shown, d.ID)
|
||||
}
|
||||
go func() {
|
||||
@@ -466,11 +476,11 @@ func (m *model) openPresets() {
|
||||
items = append(items, agent.Option{Value: d.ID, Note: d.Name + " · " + kindNote(d.Kind)})
|
||||
}
|
||||
for _, c := range customAPIs {
|
||||
items = append(items, agent.Option{Value: c.id, Note: "your own · " + c.name + " API, at its address"})
|
||||
items = append(items, agent.Option{Value: c.id, Note: trf("your own · %s API, at its address", tr(c.name))})
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: []string{"providers", "add"},
|
||||
input: newInput("a vendor magpie knows, or custom for your own API"),
|
||||
crumbs: []string{tr("providers"), tr("add")},
|
||||
input: newInput(tr("a vendor magpie knows, or custom for your own API")),
|
||||
items: items,
|
||||
onPick: func(id string) tea.Cmd {
|
||||
if i := slices.IndexFunc(customAPIs, func(c customAPI) bool { return c.id == id }); i >= 0 {
|
||||
@@ -488,7 +498,7 @@ func (m *model) openPresets() {
|
||||
// magpie, Azure OpenAI) has none of the preset's: it is
|
||||
// asked for first, as the app's editor asks it
|
||||
if pr := provider.Preset(id); pr != nil && pr.Endpoint != "" {
|
||||
return askMsg{endpointAsk(*pr, []string{"providers", "add", p.Name, "address"}, "", func(addr string) tea.Cmd {
|
||||
return askMsg{endpointAsk(*pr, []string{tr("providers"), tr("add"), p.Name, tr("address")}, "", func(addr string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
p.Chat, p.Responses = addr, addr
|
||||
return askMsg{addKeyAsk(p)}
|
||||
@@ -498,7 +508,7 @@ func (m *model) openPresets() {
|
||||
// a local server can listen on another port, or be another
|
||||
// computer's: asked first, Enter alone keeping the preset's
|
||||
if pr := provider.Preset(id); pr != nil && pr.Kind == provider.KindLocal {
|
||||
return askMsg{localAddressAsk(*pr, []string{"providers", "add", p.Name, "address"}, "", func(addr string) tea.Cmd {
|
||||
return askMsg{localAddressAsk(*pr, []string{tr("providers"), tr("add"), p.Name, tr("address")}, "", func(addr string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
_ = p.AtAddress(addr)
|
||||
return askMsg{addKeyAsk(p)}
|
||||
@@ -534,17 +544,17 @@ var customAPIs = []customAPI{
|
||||
// customURLAsk asks for the base URL of a provider of the user's own on
|
||||
// api, then its name and its key, and adds it.
|
||||
func customURLAsk(api customAPI) ask {
|
||||
return ask{crumbs: []string{"providers", "add", "custom", "base URL"}, input: newInput(api.example),
|
||||
hint: api.name + " · the base URL, e.g. " + api.example, empty: true,
|
||||
return ask{crumbs: []string{tr("providers"), tr("add"), tr("custom"), tr("base URL")}, input: newInput(api.example),
|
||||
hint: tr(api.name) + " · " + trf("the base URL, e.g. %s", api.example), empty: true,
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
u, err := url.Parse(v)
|
||||
if v == "" || err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
|
||||
return flashMsg{text: "the base URL is an http:// or https:// address, e.g. " + api.example}
|
||||
return flashMsg{text: trf("the base URL is an http:// or https:// address, e.g. %s", api.example)}
|
||||
}
|
||||
in := newInput(u.Hostname())
|
||||
return askMsg{ask{crumbs: []string{"providers", "add", "custom", "name"}, input: in,
|
||||
hint: "its name in magpie · enter for " + u.Hostname(), empty: true,
|
||||
return askMsg{ask{crumbs: []string{tr("providers"), tr("add"), tr("custom"), tr("name")}, input: in,
|
||||
hint: trf("its name in magpie · enter for %s", u.Hostname()), empty: true,
|
||||
onEnter: func(name string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if name == "" {
|
||||
@@ -591,14 +601,14 @@ func customURLsAsk(p provider.Provider, apis []customAPI, typed []string) ask {
|
||||
api := apis[len(typed)]
|
||||
in := newInput(api.example)
|
||||
in.SetValue(customURLOf(p, api))
|
||||
return ask{crumbs: []string{"providers", p.Name, "base URL"}, input: in, empty: true,
|
||||
hint: api.name + " · enter keeps it",
|
||||
return ask{crumbs: []string{tr("providers"), p.Name, tr("base URL")}, input: in, empty: true,
|
||||
hint: tr(api.name) + " · " + tr("enter keeps it"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if v != "" {
|
||||
u, err := url.Parse(v)
|
||||
if err != nil || (u.Scheme != "http" && u.Scheme != "https") || u.Host == "" {
|
||||
return flashMsg{text: "the base URL is an http:// or https:// address, e.g. " + api.example}
|
||||
return flashMsg{text: trf("the base URL is an http:// or https:// address, e.g. %s", api.example)}
|
||||
}
|
||||
}
|
||||
typed := append(slices.Clone(typed), strings.TrimRight(v, "/"))
|
||||
@@ -614,28 +624,28 @@ func customURLsAsk(p provider.Provider, apis []customAPI, typed []string) ask {
|
||||
}
|
||||
}
|
||||
if len(set) == 0 {
|
||||
return flashMsg{text: p.Name + " base URL unchanged", ok: true}
|
||||
return flashMsg{text: trf("%s base URL unchanged", p.Name), ok: true}
|
||||
}
|
||||
return saveProvider(p.ID, func(q *provider.Provider) {
|
||||
for _, i := range set {
|
||||
apis[i].set(q, typed[i])
|
||||
}
|
||||
provider.ForgetBalances()
|
||||
}, p.Name+" base URL "+strings.Join(said, " · "))()
|
||||
}, trf("%s base URL %s", p.Name, strings.Join(said, " · ")))()
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
||||
// addKeyAsk asks for the key of p, a preset's provider, and adds it.
|
||||
func addKeyAsk(p provider.Provider) ask {
|
||||
in := newInput("the API key")
|
||||
in := newInput(tr("the API key"))
|
||||
in.EchoMode = textinput.EchoPassword
|
||||
in.EchoCharacter = '•'
|
||||
hint := "the key is kept in magpie's providers file"
|
||||
hint := tr("the key is kept in magpie's providers file")
|
||||
if p.KeysURL != "" {
|
||||
hint = "keys: " + p.KeysURL
|
||||
hint = trf("keys: %s", p.KeysURL)
|
||||
}
|
||||
return ask{crumbs: []string{"providers", "add", p.Name}, input: in, hint: hint, empty: true,
|
||||
return ask{crumbs: []string{tr("providers"), tr("add"), p.Name}, input: in, hint: hint, empty: true,
|
||||
onEnter: func(key string) tea.Cmd {
|
||||
p.Key = key
|
||||
return addCmd(p)
|
||||
@@ -648,9 +658,9 @@ func addKeyAsk(p provider.Provider) ask {
|
||||
// set from the CLI, as its location is. Nothing typed is said to be needed,
|
||||
// as Save says it.
|
||||
func vertexProjectAsk(p provider.Provider) ask {
|
||||
return ask{crumbs: []string{"providers", "add", p.Name, "project"}, input: newInput("your Google Cloud project's id"), empty: true,
|
||||
hint: "no key: signed with gcloud's Application Default Credentials (gcloud auth application-default login)\n" +
|
||||
"magpie provider set " + provider.FreeID(p.ID) + " location=… credentials=… impersonate=… changes the rest",
|
||||
return ask{crumbs: []string{tr("providers"), tr("add"), p.Name, tr("project")}, input: newInput(tr("your Google Cloud project's id")), empty: true,
|
||||
hint: tr("no key: signed with gcloud's Application Default Credentials (gcloud auth application-default login)") + "\n" +
|
||||
trf("magpie provider set %s location=… credentials=… impersonate=… changes the rest", provider.FreeID(p.ID)),
|
||||
onEnter: func(project string) tea.Cmd {
|
||||
p.Vertex = &provider.Vertex{Project: project}
|
||||
return addCmd(p)
|
||||
@@ -674,7 +684,7 @@ func addCmd(p provider.Provider) tea.Cmd {
|
||||
// the vendor's list, and what came of asking it: a list that
|
||||
// failed said so, not an "added" over 0 models (akic404 on
|
||||
// Discord)
|
||||
text := "added " + saved.Name
|
||||
text := trf("added %s", saved.Name)
|
||||
ms, err := saved.Fetch(ctx)
|
||||
if err != nil && saved.DecideOnly() {
|
||||
// a System One API: its list isn't what it is for
|
||||
@@ -697,14 +707,14 @@ func endpointAsk(pr provider.PresetDef, crumbs []string, now string, then func(s
|
||||
in.SetValue(now)
|
||||
hint := pr.EndpointHint
|
||||
if hint == "" {
|
||||
hint = "the address it is reached at, e.g. " + pr.Endpoint
|
||||
hint = trf("the address it is reached at, e.g. %s", pr.Endpoint)
|
||||
}
|
||||
return ask{crumbs: crumbs, input: in, hint: hint, empty: true,
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
if v == "" {
|
||||
need := pr.EndpointNeeded
|
||||
if need == "" {
|
||||
need = "Your resource's endpoint is needed"
|
||||
need = tr("Your resource's endpoint is needed")
|
||||
}
|
||||
return func() tea.Msg { return flashMsg{text: need} }
|
||||
}
|
||||
@@ -719,7 +729,7 @@ func localAddressAsk(pr provider.PresetDef, crumbs []string, now string, then fu
|
||||
in := newInput(provider.AddressOf(pr.Chat, pr.Responses, pr.Anthropic))
|
||||
in.SetValue(now)
|
||||
return ask{crumbs: crumbs, input: in, empty: true,
|
||||
hint: "where the server listens: another port, or another computer's address",
|
||||
hint: tr("where the server listens: another port, or another computer's address"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
if _, err := provider.AtAddress(pr, v); err != nil {
|
||||
return func() tea.Msg { return flashMsg{text: err.Error()} }
|
||||
@@ -743,7 +753,7 @@ func (m model) viewProviders() string {
|
||||
}
|
||||
if len(m.provs) == 0 {
|
||||
if m.provsErr == nil {
|
||||
b.WriteString(pad + " " + sMuted.Render("no providers yet · a adds one"))
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("no providers yet · a adds one")))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -754,49 +764,49 @@ func (m model) viewProviders() string {
|
||||
r := row{name: p.Name, id: p.ID}
|
||||
switch {
|
||||
case p.Off:
|
||||
r.key = "○ switched off"
|
||||
r.key = "○ " + tr("switched off")
|
||||
case p.Account != nil && signedOut(p):
|
||||
// every account in use refused, as magpie providers says it
|
||||
r.key = "○ " + p.AccountShown(p.Account.User) + " is signed out"
|
||||
r.key = "○ " + trf("%s is signed out", p.AccountShown(p.Account.User))
|
||||
case p.Account != nil:
|
||||
r.key = "● " + p.AccountShown(p.Account.User)
|
||||
case p.IsVertex() && !p.Ready():
|
||||
r.key = "○ needs a project"
|
||||
r.key = "○ " + tr("needs a project")
|
||||
case p.IsVertex():
|
||||
// no key: a token minted from the user's Google credentials,
|
||||
// as magpie providers says it
|
||||
r.key = "● Google credentials"
|
||||
r.key = "● " + tr("Google credentials")
|
||||
if p.Vertex != nil && p.Vertex.Impersonate != "" {
|
||||
r.key += " as " + p.Vertex.Impersonate
|
||||
r.key += " " + trf("as %s", p.Vertex.Impersonate)
|
||||
}
|
||||
case p.Key != "":
|
||||
r.key = "● " + provider.Mask(p.Key)
|
||||
case p.Ready():
|
||||
r.key = "● no key needed"
|
||||
r.key = "● " + tr("no key needed")
|
||||
default:
|
||||
r.key = "○ no key"
|
||||
r.key = "○ " + tr("no key")
|
||||
}
|
||||
r.models = fmt.Sprintf("%d models", len(p.Exposed()))
|
||||
r.models = trf("%d models", len(p.Exposed()))
|
||||
var notes []string
|
||||
if p.Off {
|
||||
// how to switch it on again, as magpie providers says it
|
||||
notes = append(notes, "o switches it on")
|
||||
notes = append(notes, tr("o switches it on"))
|
||||
}
|
||||
if v, ok := m.bal[p.ID]; ok {
|
||||
notes = append(notes, v)
|
||||
}
|
||||
if p.Family != "" {
|
||||
notes = append(notes, "family "+p.Family)
|
||||
notes = append(notes, trf("family %s", p.Family))
|
||||
}
|
||||
if p.Unlisted {
|
||||
notes = append(notes, "groups only")
|
||||
notes = append(notes, tr("groups only"))
|
||||
}
|
||||
r.note = strings.Join(notes, " · ")
|
||||
// a plugin's account showing its defaults alone says why, as the
|
||||
// app's editor does (gnayiab on X: Cursor in WSL's TUI had Auto
|
||||
// alone and nothing said)
|
||||
if e := listError(p); e != "" {
|
||||
r.warn = "couldn't list its models: " + e
|
||||
r.warn = trf("couldn't list its models: %s", e)
|
||||
}
|
||||
for i, s := range []string{r.name, r.id, r.key, r.models} {
|
||||
w[i] = max(w[i], lipgloss.Width(s))
|
||||
@@ -987,7 +997,7 @@ func checkinCmd() tea.Msg {
|
||||
}
|
||||
}
|
||||
if len(parts) == 0 {
|
||||
return checkinMsg{text: "no WorkBuddy (China), Trae CN, MiniMax Code, Qoder or check-in plugin account is signed in · only they have the daily check-in"}
|
||||
return checkinMsg{text: tr("no WorkBuddy (China), Trae CN, MiniMax Code, Qoder or check-in plugin account is signed in · only they have the daily check-in")}
|
||||
}
|
||||
return checkinMsg{text: strings.Join(parts, "; "), ok: failed == 0}
|
||||
}
|
||||
@@ -1022,31 +1032,31 @@ func checkinWords(r provider.WorkBuddyCheckin) string {
|
||||
}
|
||||
switch r.Outcome {
|
||||
case provider.CheckinClaimed, provider.CheckinDone:
|
||||
s := who + " checked in today"
|
||||
s := trf("%s checked in today", who)
|
||||
if r.Credit > 0 {
|
||||
s += fmt.Sprintf(" +%g", r.Credit)
|
||||
}
|
||||
if r.Streak > 0 {
|
||||
s += fmt.Sprintf(" · a %d-day streak", r.Streak)
|
||||
s += " · " + trf("a %d-day streak", r.Streak)
|
||||
}
|
||||
if r.Outcome == provider.CheckinDone || !r.Asked {
|
||||
s += " · already"
|
||||
s += " · " + tr("already")
|
||||
}
|
||||
return s
|
||||
case provider.CheckinIneligible:
|
||||
return who + " isn't eligible for the check-in" + checkinWhy(r)
|
||||
return trf("%s isn't eligible for the check-in", who) + checkinWhy(r)
|
||||
case provider.CheckinInactive:
|
||||
return who + ": no check-in event now" + checkinWhy(r)
|
||||
return who + ": " + tr("no check-in event now") + checkinWhy(r)
|
||||
case provider.CheckinCaptcha:
|
||||
return who + " asks for a captcha: check in in its own app"
|
||||
return trf("%s asks for a captcha: check in in its own app", who)
|
||||
case provider.CheckinOwnApp:
|
||||
return who + ": " + ownAppWords(r)
|
||||
}
|
||||
msg := r.Msg
|
||||
if msg == "" {
|
||||
msg = "no answer"
|
||||
msg = tr("no answer")
|
||||
}
|
||||
return who + " couldn't check in: " + msg
|
||||
return trf("%s couldn't check in: %s", who, msg)
|
||||
}
|
||||
|
||||
// checkinWhy is why an inactive or ineligible check-in had nothing to
|
||||
@@ -1067,11 +1077,11 @@ func checkinWhy(r provider.WorkBuddyCheckin) string {
|
||||
func againWords(r provider.WorkBuddyCheckin) string {
|
||||
switch r.Outcome {
|
||||
case provider.CheckinDone:
|
||||
return "says already checked in · its day may not have turned, magpie asks again later"
|
||||
return tr("says already checked in · its day may not have turned, magpie asks again later")
|
||||
case provider.CheckinIneligible:
|
||||
return "not eligible now · magpie asks again later"
|
||||
return tr("not eligible now · magpie asks again later")
|
||||
}
|
||||
return "no check-in event now · magpie asks again later"
|
||||
return tr("no check-in event now · magpie asks again later")
|
||||
}
|
||||
|
||||
// ownAppName is the vendor whose own app alone gets r's check-in credits.
|
||||
@@ -1084,7 +1094,7 @@ func ownAppName(r provider.WorkBuddyCheckin) string {
|
||||
case r.By == "":
|
||||
return "WorkBuddy"
|
||||
}
|
||||
return "the vendor"
|
||||
return tr("the vendor")
|
||||
}
|
||||
|
||||
// ownAppWords says a check-in the vendor pays only to its own app is to
|
||||
@@ -1092,10 +1102,10 @@ func ownAppName(r provider.WorkBuddyCheckin) string {
|
||||
// refused it; that only its app is paid isn't so (#1920).
|
||||
func ownAppWords(r provider.WorkBuddyCheckin) string {
|
||||
if r.By == "trae" {
|
||||
return provider.TraeRefusedWords
|
||||
return tr(provider.TraeRefusedWords)
|
||||
}
|
||||
name := ownAppName(r)
|
||||
return name + " only gives check-in credits to its own app; check in in the " + name + " app"
|
||||
return trf("%[1]s only gives check-in credits to its own app; check in in the %[1]s app", name)
|
||||
}
|
||||
|
||||
// whyHint points an inactive or ineligible check-in's line to c when its
|
||||
@@ -1104,7 +1114,7 @@ func whyHint(r provider.WorkBuddyCheckin) string {
|
||||
if checkinWhy(r) == "" {
|
||||
return ""
|
||||
}
|
||||
return " · c says why"
|
||||
return " · " + tr("c says why")
|
||||
}
|
||||
|
||||
// checkinCell is a WorkBuddy (China) or Trae CN account's check-in on its
|
||||
@@ -1116,11 +1126,11 @@ func checkinCell(q provider.SubscriptionQuota, now time.Time) string {
|
||||
}
|
||||
r := q.Checkin
|
||||
if r == nil || r.Day != provider.CheckinDay(now) {
|
||||
return sMuted.Render("签到 not yet today · c")
|
||||
return sMuted.Render(tr("签到 not yet today · c"))
|
||||
}
|
||||
if r.Again && r.Outcome == provider.CheckinDone {
|
||||
// "already in" that may be the vendor's day before (#3326)
|
||||
return sMuted.Render("签到 said already · asked again later · c")
|
||||
return sMuted.Render(tr("签到 said already · asked again later · c"))
|
||||
}
|
||||
switch r.Outcome {
|
||||
case provider.CheckinClaimed, provider.CheckinDone:
|
||||
@@ -1129,24 +1139,24 @@ func checkinCell(q provider.SubscriptionQuota, now time.Time) string {
|
||||
s += sText.Render(fmt.Sprintf(" +%g", r.Credit))
|
||||
}
|
||||
if r.Streak > 0 {
|
||||
s += sFaint.Render(fmt.Sprintf(" · %d-day streak", r.Streak))
|
||||
s += sFaint.Render(" · " + trf("%d-day streak", r.Streak))
|
||||
}
|
||||
return s
|
||||
// the reason is long (plugins#304): the line points to c, whose
|
||||
// answer says it (checkinWords)
|
||||
case provider.CheckinIneligible:
|
||||
return sMuted.Render("签到 not eligible" + whyHint(*r))
|
||||
return sMuted.Render(tr("签到 not eligible") + whyHint(*r))
|
||||
case provider.CheckinInactive:
|
||||
return sMuted.Render("签到 no event now" + whyHint(*r))
|
||||
return sMuted.Render(tr("签到 no event now") + whyHint(*r))
|
||||
case provider.CheckinCaptcha:
|
||||
return sMuted.Render("签到 needs a captcha · check in in its app")
|
||||
return sMuted.Render(tr("签到 needs a captcha · check in in its app"))
|
||||
case provider.CheckinOwnApp:
|
||||
if r.By == "trae" {
|
||||
return sMuted.Render("签到 refused by Trae CN (9074) · check in in its app")
|
||||
return sMuted.Render(tr("签到 refused by Trae CN (9074) · check in in its app"))
|
||||
}
|
||||
return sMuted.Render("签到 only in " + ownAppName(*r) + "'s own app · check in there")
|
||||
return sMuted.Render(trf("签到 only in %s's own app · check in there", ownAppName(*r)))
|
||||
}
|
||||
return sBad.Render("签到 failed") + sMuted.Render(" · c tries again")
|
||||
return sBad.Render(tr("签到 failed")) + sMuted.Render(" · "+tr("c tries again"))
|
||||
}
|
||||
|
||||
func (m model) updateUsage(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
@@ -1164,7 +1174,7 @@ func (m model) updateUsage(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
case "c":
|
||||
// WorkBuddy's daily check-in, as the app's "Check in now"
|
||||
m.flash, m.flashOK = "checking in…", true
|
||||
m.flash, m.flashOK = tr("checking in…"), true
|
||||
return m, checkinCmd
|
||||
case "l", "right":
|
||||
m.period = periods[(i+1)%len(periods)]
|
||||
@@ -1242,7 +1252,7 @@ func fmtCost(t usage.Totals) string { return fmtCostOf(t, "") }
|
||||
// (its own, with the choice "provider"); "" is a sum of several.
|
||||
func fmtCostOf(t usage.Totals, providerID string) string {
|
||||
if t.Cost == 0 && t.Unpriced > 0 {
|
||||
return "no price"
|
||||
return tr("no price")
|
||||
}
|
||||
st, rate, yuan := costCurrency()
|
||||
cncy := st.TotalCostIn()
|
||||
@@ -1275,9 +1285,9 @@ func (m model) viewUsage() string {
|
||||
var tabs []string
|
||||
for _, p := range periods {
|
||||
if p == s.Period {
|
||||
tabs = append(tabs, sPill.Render(periodNames[p]))
|
||||
tabs = append(tabs, sPill.Render(tr(periodNames[p])))
|
||||
} else {
|
||||
tabs = append(tabs, sMuted.Render(" "+periodNames[p]+" "))
|
||||
tabs = append(tabs, sMuted.Render(" "+tr(periodNames[p])+" "))
|
||||
}
|
||||
}
|
||||
b.WriteString(pad + " " + strings.Join(tabs, " ") + "\n\n")
|
||||
@@ -1290,7 +1300,7 @@ func (m model) viewUsage() string {
|
||||
}
|
||||
d := m.direct
|
||||
if s.Calls == 0 && d.Calls == 0 {
|
||||
b.WriteString(pad + " " + sMuted.Render("no calls in this time · route an agent through magpie and its usage shows up here"))
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("no calls in this time · route an agent through magpie and its usage shows up here")))
|
||||
return b.String()
|
||||
}
|
||||
names := map[string]string{}
|
||||
@@ -1302,14 +1312,14 @@ func (m model) viewUsage() string {
|
||||
room = max(2, room/2)
|
||||
}
|
||||
if s.Calls == 0 {
|
||||
b.WriteString(pad + " " + sMuted.Render("no calls through magpie in this time") + "\n\n")
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("no calls through magpie in this time")) + "\n\n")
|
||||
} else {
|
||||
m.usageBlock(&b, s, room, names)
|
||||
}
|
||||
// the calls the agents made on their own, as the app's Requests tab
|
||||
// counts them beside the gateway's (Kumo31 on Discord)
|
||||
if d.Calls > 0 {
|
||||
b.WriteString(pad + " " + sFaint.Render("not through magpie · the agents' own requests, read from their session files") + "\n")
|
||||
b.WriteString(pad + " " + sFaint.Render(tr("not through magpie · the agents' own requests, read from their session files")) + "\n")
|
||||
m.usageBlock(&b, d, room, names)
|
||||
}
|
||||
return strings.TrimRight(b.String(), "\n")
|
||||
@@ -1318,19 +1328,19 @@ func (m model) viewUsage() string {
|
||||
// usageBlock is one summary's totals, timeline and agents' and models'
|
||||
// tables, the gateway's or the agents' own calls.
|
||||
func (m model) usageBlock(b *strings.Builder, s usage.Summary, room int, names map[string]string) {
|
||||
line := sName.Render(fmtTokens(s.Tokens())+" tokens") + sMuted.Render(fmt.Sprintf(" · %d call%s · ", s.Calls, plural(s.Calls))) + sOK.Render(fmtCost(s.Totals))
|
||||
line := sName.Render(trf("%s tokens", fmtTokens(s.Tokens()))) + sMuted.Render(" · "+trf("%d call%s", s.Calls, plural(s.Calls))+" · ") + sOK.Render(fmtCost(s.Totals))
|
||||
if s.Unpriced > 0 { // calls with no known price, not in the cost (#1856)
|
||||
line += sMuted.Render(fmt.Sprintf(" (%d call%s unpriced)", s.Unpriced, plural(s.Unpriced)))
|
||||
line += sMuted.Render(" " + trf("(%d call%s unpriced)", s.Unpriced, plural(s.Unpriced)))
|
||||
}
|
||||
line += sMuted.Render(credits(s.Totals))
|
||||
if s.Errors > 0 {
|
||||
line += sMuted.Render(" · ") + sBad.Render(fmt.Sprintf("%d error%s", s.Errors, plural(s.Errors)))
|
||||
line += sMuted.Render(" · ") + sBad.Render(trf("%d error%s", s.Errors, plural(s.Errors)))
|
||||
}
|
||||
if s.Retried > 0 { // answered after a try that failed first, not an error
|
||||
line += sMuted.Render(fmt.Sprintf(" · %d answered on a retry", s.Retried))
|
||||
line += sMuted.Render(" · " + trf("%d answered on a retry", s.Retried))
|
||||
}
|
||||
b.WriteString(pad + " " + line + "\n")
|
||||
b.WriteString(pad + " " + sMuted.Render("in "+fmtTokens(s.Input)+" out "+fmtTokens(s.Output)+" cache read "+fmtTokens(s.CacheRead)+" cache write "+fmtTokens(s.CacheWrite)+" reasoning "+fmtTokens(s.Reasoning)) + "\n\n")
|
||||
b.WriteString(pad + " " + sMuted.Render(trf("in %s out %s cache read %s cache write %s reasoning %s", fmtTokens(s.Input), fmtTokens(s.Output), fmtTokens(s.CacheRead), fmtTokens(s.CacheWrite), fmtTokens(s.Reasoning))) + "\n\n")
|
||||
|
||||
// the timeline, one bar a bucket
|
||||
top := 0
|
||||
@@ -1358,21 +1368,21 @@ func (m model) usageBlock(b *strings.Builder, s usage.Summary, room int, names m
|
||||
}
|
||||
for i, g := range gs {
|
||||
if i == room {
|
||||
b.WriteString(pad + " " + sFaint.Render(fmt.Sprintf("and %d more · magpie usage", len(gs)-room)) + "\n")
|
||||
b.WriteString(pad + " " + sFaint.Render(trf("and %d more · magpie usage", len(gs)-room)) + "\n")
|
||||
break
|
||||
}
|
||||
share := fmt.Sprintf("%3.0f%%", 100*float64(g.Tokens())/float64(max(1, s.Tokens())))
|
||||
b.WriteString(pad + " " + sText.Render(padRight(name(g), w)) + " " + sMuted.Render(share) + " " + sText.Render(padRight(fmtTokens(g.Tokens()), 7)) + " " + sFaint.Render(padRight(fmt.Sprintf("%d call%s", g.Calls, plural(g.Calls)), 10)) + " " + sOK.Render(fmtCostOf(g.Totals, g.Provider)) + sMuted.Render(credits(g.Totals)) + "\n")
|
||||
b.WriteString(pad + " " + sText.Render(padRight(name(g), w)) + " " + sMuted.Render(share) + " " + sText.Render(padRight(fmtTokens(g.Tokens()), 7)) + " " + sFaint.Render(padRight(trf("%d call%s", g.Calls, plural(g.Calls)), 10)) + " " + sOK.Render(fmtCostOf(g.Totals, g.Provider)) + sMuted.Render(credits(g.Totals)) + "\n")
|
||||
}
|
||||
b.WriteString("\n")
|
||||
}
|
||||
table("agents", s.Agents, func(g usage.Group) string {
|
||||
table(tr("agents"), s.Agents, func(g usage.Group) string {
|
||||
if n := names[g.ID]; n != "" {
|
||||
return n
|
||||
}
|
||||
return g.ID
|
||||
})
|
||||
table("models", s.Models, func(g usage.Group) string {
|
||||
table(tr("models"), s.Models, func(g usage.Group) string {
|
||||
if g.Provider == usage.UnknownProvider {
|
||||
return g.Model // a session file's call whose provider isn't known
|
||||
}
|
||||
@@ -1389,7 +1399,7 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
if !asked {
|
||||
return nil
|
||||
}
|
||||
return []string{sFaint.Render("accounts"), sMuted.Render("asking the vendors what is left…")}
|
||||
return []string{sFaint.Render(tr("accounts")), sMuted.Render(tr("asking the vendors what is left…"))}
|
||||
}
|
||||
if len(qs) == 0 {
|
||||
return nil
|
||||
@@ -1417,9 +1427,9 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
tw = max(tw, lipgloss.Width(p))
|
||||
}
|
||||
tw = min(tw, 44)
|
||||
head := "accounts · % is how much is used"
|
||||
head := tr("accounts · % is how much is used")
|
||||
if left {
|
||||
head = "accounts · % is how much is left"
|
||||
head = tr("accounts · % is how much is left")
|
||||
}
|
||||
out := []string{sFaint.Render(head)}
|
||||
for _, q := range qs {
|
||||
@@ -1435,7 +1445,7 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
}
|
||||
switch {
|
||||
case q.Balance != "" && len(q.Windows) == 0:
|
||||
c := sText.Render(q.Balance) + sMuted.Render(" left")
|
||||
c := sText.Render(q.Balance) + sMuted.Render(" "+tr("left"))
|
||||
if len(q.BalanceSplit) > 0 {
|
||||
// what it is made of: DeepSeek's granted credit apart
|
||||
c += sFaint.Render(" (" + provider.SplitWords(q.BalanceSplit) + ")")
|
||||
@@ -1446,7 +1456,7 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
out = append(out, line+" "+sMuted.Render(trunc(q.Error, max(20, width-tw-2-lipgloss.Width(ci))))+ci)
|
||||
continue
|
||||
case len(q.Windows) == 0:
|
||||
out = append(out, line+" "+sMuted.Render("no usage reported")+ci)
|
||||
out = append(out, line+" "+sMuted.Render(tr("no usage reported"))+ci)
|
||||
continue
|
||||
}
|
||||
// the windows follow the name, those that don't fit on lines below
|
||||
@@ -1457,9 +1467,9 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
cells = append(cells, quotaCell(w, left, now))
|
||||
}
|
||||
if q.Balance != "" {
|
||||
c := sText.Render(q.Balance) + sMuted.Render(" left")
|
||||
c := sText.Render(q.Balance) + sMuted.Render(" "+tr("left"))
|
||||
if q.Provider == "codex" && q.User != "" && !provider.CodexCredits(q.User) {
|
||||
c += sFaint.Render(" · not spent") // held once a window is used up
|
||||
c += sFaint.Render(" · " + tr("not spent")) // held once a window is used up
|
||||
}
|
||||
cells = append(cells, c)
|
||||
}
|
||||
@@ -1469,7 +1479,7 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
if r := q.Resets; r != nil {
|
||||
c := sText.Render("↺ " + r.Words())
|
||||
if r.Until != nil {
|
||||
c += sFaint.Render(" until " + provider.ResetClock(*r.Until, now))
|
||||
c += sFaint.Render(" " + trf("until %s", provider.ResetClock(*r.Until, now)))
|
||||
}
|
||||
if q.Provider == "codex" {
|
||||
if auto := provider.AutoResetWords(q.User); auto != "" {
|
||||
@@ -1497,12 +1507,12 @@ func quotaLines(qs []provider.SubscriptionQuota, asked, left bool, width int, no
|
||||
// and when it starts again: on the clock, and how long until then.
|
||||
func quotaCell(w provider.QuotaWindow, left bool, now time.Time) string {
|
||||
if w.Unlimited {
|
||||
return sMuted.Render(w.Name) + " " + sText.Render("Unlimited")
|
||||
return sMuted.Render(w.Name) + " " + sText.Render(tr("Unlimited"))
|
||||
}
|
||||
used := int(math.Round(math.Max(0, math.Min(100, w.Used))))
|
||||
n, word := used, "used"
|
||||
n, word := used, tr("used")
|
||||
if left {
|
||||
n, word = 100-used, "left"
|
||||
n, word = 100-used, tr("left")
|
||||
}
|
||||
const cells = 8
|
||||
on := (n*cells + 50) / 100
|
||||
@@ -1540,11 +1550,11 @@ func until(d time.Duration) string {
|
||||
h := int(math.Round(float64(mins) / 60))
|
||||
switch {
|
||||
case mins < 60:
|
||||
return fmt.Sprintf("%dm", mins)
|
||||
return trf("%dm", mins)
|
||||
case h < 48:
|
||||
return fmt.Sprintf("%dh", h)
|
||||
return trf("%dh", h)
|
||||
}
|
||||
return fmt.Sprintf("%dd", int(math.Round(float64(h)/24)))
|
||||
return trf("%dd", int(math.Round(float64(h)/24)))
|
||||
}
|
||||
|
||||
// ---- a line to type ---------------------------------------------------------
|
||||
|
||||
+104
-104
@@ -73,35 +73,35 @@ var routings = []string{"", provider.Ordered, provider.Rotate, provider.LeastUse
|
||||
func routingName(v string) string {
|
||||
switch v {
|
||||
case provider.Ordered:
|
||||
return "in order"
|
||||
return tr("in order")
|
||||
case provider.Rotate:
|
||||
return "rotate"
|
||||
return tr("rotate")
|
||||
case provider.LeastUsed:
|
||||
return "least used"
|
||||
return tr("least used")
|
||||
case provider.Pace:
|
||||
return "weekly pace"
|
||||
return tr("weekly pace")
|
||||
case provider.Weighted:
|
||||
return "by weight"
|
||||
return tr("by weight")
|
||||
case provider.FreeFirst:
|
||||
return "free first"
|
||||
return tr("free first")
|
||||
case provider.Fastest:
|
||||
return "speed first"
|
||||
return tr("speed first")
|
||||
case provider.Cheapest:
|
||||
return "cheapest first"
|
||||
return tr("cheapest first")
|
||||
case provider.Drain:
|
||||
return "until used up"
|
||||
return tr("until used up")
|
||||
case provider.FreeExpiring:
|
||||
return "free, soonest to expire"
|
||||
return tr("free, soonest to expire")
|
||||
case provider.Manual:
|
||||
return "manual"
|
||||
return tr("manual")
|
||||
}
|
||||
return "smart"
|
||||
return tr("smart")
|
||||
}
|
||||
|
||||
// groupRouting is how a group routes: a manual one names its pick.
|
||||
func groupRouting(g provider.Group) string {
|
||||
if g.Routing == provider.Manual {
|
||||
return "manual → " + g.Picked()
|
||||
return tr("manual") + " → " + g.Picked()
|
||||
}
|
||||
return routingName(g.Routing)
|
||||
}
|
||||
@@ -109,15 +109,15 @@ func groupRouting(g provider.Group) string {
|
||||
func staysName(v string) string {
|
||||
switch v {
|
||||
case provider.AffinitySession:
|
||||
return "stays the session"
|
||||
return tr("stays the session")
|
||||
case provider.AffinityTurn:
|
||||
return "stays a turn"
|
||||
return tr("stays a turn")
|
||||
case provider.AffinityOff:
|
||||
return "never stays"
|
||||
return tr("never stays")
|
||||
case provider.AffinityStrict:
|
||||
return "stays strictly"
|
||||
return tr("stays strictly")
|
||||
}
|
||||
return "stays auto"
|
||||
return tr("stays auto")
|
||||
}
|
||||
|
||||
// saveGroup changes one group and saves it: one magpie found becomes the
|
||||
@@ -126,7 +126,7 @@ func saveGroup(id string, change func(*provider.Group) error, done string) tea.C
|
||||
return func() tea.Msg {
|
||||
g, ok := findGroup(id)
|
||||
if !ok {
|
||||
return flashMsg{text: "no group " + id}
|
||||
return flashMsg{text: trf("no group %s", id)}
|
||||
}
|
||||
if err := change(&g); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
@@ -178,8 +178,8 @@ func (m model) updateGroups(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
return m, nil
|
||||
case "n":
|
||||
m.openAsk(ask{crumbs: []string{"routing", "new"}, input: newInput("the group's name, e.g. opus-anywhere"),
|
||||
hint: "then pick its first model; agents choose it as group/<id>",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), tr("new")}, input: newInput(tr("the group's name, e.g. opus-anywhere")),
|
||||
hint: tr("then pick its first model; agents choose it as group/<id>"),
|
||||
onEnter: func(name string) tea.Cmd {
|
||||
return func() tea.Msg { return pickMsg{newGroup: name} }
|
||||
}})
|
||||
@@ -195,11 +195,11 @@ func (m model) updateGroups(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if err := provider.ShowGroup(g.ID); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "brought " + g.ID + " back", ok: true}
|
||||
return flashMsg{text: trf("brought %s back", g.ID), ok: true}
|
||||
}
|
||||
}
|
||||
if key != "r" {
|
||||
m.flash, m.flashOK = g.ID+" was removed · u brings it back", false
|
||||
m.flash, m.flashOK = trf("%s was removed · u brings it back", g.ID), false
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -208,11 +208,11 @@ func (m model) updateGroups(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.gid, m.gsel = g.ID, 0
|
||||
m.mode = modeGroup
|
||||
case "o":
|
||||
return m, saveGroup(g.ID, nextRouting, g.Name+" routing changed")
|
||||
return m, saveGroup(g.ID, nextRouting, trf("%s routing changed", g.Name))
|
||||
case "d":
|
||||
if m.confirm != "group/"+g.ID {
|
||||
m.confirm = "group/" + g.ID
|
||||
m.flash, m.flashOK = "press d again to remove "+g.Name, false
|
||||
m.flash, m.flashOK = trf("press d again to remove %s", g.Name), false
|
||||
return m, nil
|
||||
}
|
||||
m.confirm = ""
|
||||
@@ -220,7 +220,7 @@ func (m model) updateGroups(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if err := provider.DeleteGroup(g.ID); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "removed " + g.Name, ok: true}
|
||||
return flashMsg{text: trf("removed %s", g.Name), ok: true}
|
||||
}
|
||||
}
|
||||
return m, nil
|
||||
@@ -248,7 +248,7 @@ func memberOptions(skip []string, self string) []agent.Option {
|
||||
}
|
||||
note := e.Name
|
||||
if e.Group != "" {
|
||||
note = "group · " + e.Name
|
||||
note = tr("group") + " · " + e.Name
|
||||
}
|
||||
out = append(out, agent.Option{Value: e.ID, Note: note})
|
||||
}
|
||||
@@ -257,7 +257,7 @@ func memberOptions(skip []string, self string) []agent.Option {
|
||||
// those of a provider's picks, as the Routing view's picker offers
|
||||
for _, e := range provider.OfferedDeciders(nil) {
|
||||
if !slices.Contains(skip, e.ID) {
|
||||
out = append(out, agent.Option{Value: e.ID, Note: e.Name + " · decision model"})
|
||||
out = append(out, agent.Option{Value: e.ID, Note: e.Name + " · " + tr("decision model")})
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -266,16 +266,16 @@ func memberOptions(skip []string, self string) []agent.Option {
|
||||
|
||||
func (m *model) openMemberPicker(p pickMsg) {
|
||||
var skip []string
|
||||
crumbs := []string{"routing", p.newGroup, "first model"}
|
||||
empty := "magpie has no models yet · add a provider first"
|
||||
crumbs := []string{tr("routing"), p.newGroup, tr("first model")}
|
||||
empty := tr("magpie has no models yet · add a provider first")
|
||||
if p.group != "" {
|
||||
g, _ := findGroup(p.group)
|
||||
skip, crumbs = g.Members, []string{"routing", g.Name, "add a model"}
|
||||
empty = "every model magpie has is in it"
|
||||
skip, crumbs = g.Members, []string{tr("routing"), g.Name, tr("add a model")}
|
||||
empty = tr("every model magpie has is in it")
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: crumbs,
|
||||
input: newInput("filter models and groups"),
|
||||
input: newInput(tr("filter models and groups")),
|
||||
items: memberOptions(skip, p.group),
|
||||
relist: func() []agent.Option { return memberOptions(skip, p.group) },
|
||||
empty: empty,
|
||||
@@ -284,14 +284,14 @@ func (m *model) openMemberPicker(p pickMsg) {
|
||||
return saveGroup(p.group, func(g *provider.Group) error {
|
||||
g.Members = append(g.Members, id)
|
||||
return nil
|
||||
}, id+" added")
|
||||
}, trf("%s added", id))
|
||||
}
|
||||
return func() tea.Msg {
|
||||
g := provider.Group{Name: p.newGroup, Members: []string{id}}
|
||||
if err := provider.SaveGroup(g); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "made group " + p.newGroup + " · ↵ on it adds more models", ok: true}
|
||||
return flashMsg{text: trf("made group %s · ↵ on it adds more models", p.newGroup), ok: true}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -313,20 +313,20 @@ func (m *model) openClassifier(g provider.Group) {
|
||||
}
|
||||
note := e.Name
|
||||
if e.ID == g.Classifier {
|
||||
note = "● now · " + note
|
||||
note = "● " + tr("now") + " · " + note
|
||||
}
|
||||
items = append(items, agent.Option{Value: e.ID, Note: note})
|
||||
}
|
||||
return items
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: []string{"routing", g.Name, "classifier"},
|
||||
input: newInput("filter models · best a small fast one without reasoning"),
|
||||
crumbs: []string{tr("routing"), g.Name, tr("classifier")},
|
||||
input: newInput(tr("filter models · best a small fast one without reasoning")),
|
||||
items: list(),
|
||||
relist: list,
|
||||
empty: "magpie has no models yet · add a provider first",
|
||||
empty: tr("magpie has no models yet · add a provider first"),
|
||||
onPick: func(id string) tea.Cmd {
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Classifier = id; return nil }, g.Name+" classifies with "+id)
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Classifier = id; return nil }, trf("%s classifies with %s", g.Name, id))
|
||||
},
|
||||
}
|
||||
m.pk.refilter()
|
||||
@@ -346,17 +346,17 @@ or pause=<model> time=… days=… agents=… folders=… except-folders=…: th
|
||||
func (m *model) openRule(g provider.Group, i int) {
|
||||
in := newInput("use=<model> tokens=200k …")
|
||||
in.CharLimit = 400
|
||||
crumbs := []string{"routing", g.Name, "new rule"}
|
||||
crumbs := []string{tr("routing"), g.Name, tr("new rule")}
|
||||
if i >= 0 {
|
||||
in.SetValue(g.Rules[i].Line())
|
||||
in.CursorEnd()
|
||||
crumbs[2] = fmt.Sprintf("rule %d", i+1)
|
||||
crumbs[2] = trf("rule %d", i+1)
|
||||
}
|
||||
m.openAsk(ask{crumbs: crumbs, input: in, hint: ruleHint + "\nits models: " + strings.Join(g.Members, ", "),
|
||||
m.openAsk(ask{crumbs: crumbs, input: in, hint: tr(ruleHint) + "\n" + trf("its models: %s", strings.Join(g.Members, ", ")),
|
||||
onEnter: func(line string) tea.Cmd {
|
||||
done := "rule added"
|
||||
done := tr("rule added")
|
||||
if i >= 0 {
|
||||
done = fmt.Sprintf("rule %d changed", i+1)
|
||||
done = trf("rule %d changed", i+1)
|
||||
}
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { return putRule(g, i, line) }, done)
|
||||
}})
|
||||
@@ -422,12 +422,12 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, saveGroup(g.ID, func(g *provider.Group) error {
|
||||
g.Rules[from-n], g.Rules[to-n] = g.Rules[to-n], g.Rules[from-n]
|
||||
return nil
|
||||
}, fmt.Sprintf("rule %d moved to %d", from-n+1, to-n+1))
|
||||
}, trf("rule %d moved to %d", from-n+1, to-n+1))
|
||||
}
|
||||
return m, saveGroup(g.ID, func(g *provider.Group) error {
|
||||
g.Members[from], g.Members[to] = g.Members[to], g.Members[from]
|
||||
return nil
|
||||
}, g.Members[from]+" moved")
|
||||
}, trf("%s moved", g.Members[from]))
|
||||
}
|
||||
switch key {
|
||||
case "esc", "q":
|
||||
@@ -454,7 +454,7 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "c":
|
||||
if !slices.ContainsFunc(g.Rules, func(r provider.Rule) bool { return r.Intent != "" }) {
|
||||
m.flash, m.flashOK = g.Name+" has no rule with an intent to classify for · n adds one", false
|
||||
m.flash, m.flashOK = trf("%s has no rule with an intent to classify for · n adds one", g.Name), false
|
||||
return m, nil
|
||||
}
|
||||
m.openClassifier(g)
|
||||
@@ -466,14 +466,14 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
id := g.Members[m.gsel]
|
||||
if key == "F" {
|
||||
fast := !g.IsFast(id)
|
||||
said := " not fast"
|
||||
said := trf("%s not fast", id)
|
||||
if fast {
|
||||
said = " fast"
|
||||
said = trf("%s fast", id)
|
||||
}
|
||||
return m, saveGroup(g.ID, func(g *provider.Group) error {
|
||||
g.SetMemberFast(id, fast)
|
||||
return nil
|
||||
}, id+said)
|
||||
}, said)
|
||||
}
|
||||
model, effort := provider.MemberEffort(id)
|
||||
_, acct := provider.MemberAccount(id) // on its own account still
|
||||
@@ -481,36 +481,36 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, saveGroup(g.ID, func(g *provider.Group) error {
|
||||
g.RenameMember(id, to)
|
||||
return nil
|
||||
}, to+" set")
|
||||
}, trf("%s set", to))
|
||||
case "o":
|
||||
return m, saveGroup(g.ID, nextRouting, g.Name+" routing changed")
|
||||
return m, saveGroup(g.ID, nextRouting, trf("%s routing changed", g.Name))
|
||||
case "s":
|
||||
return m, saveGroup(g.ID, nextStays, g.Name+" affinity changed")
|
||||
return m, saveGroup(g.ID, nextStays, trf("%s affinity changed", g.Name))
|
||||
case "f":
|
||||
in := newInput("a tag, e.g. relay")
|
||||
in := newInput(tr("a tag, e.g. relay"))
|
||||
in.SetValue(g.Family)
|
||||
m.openAsk(ask{crumbs: []string{"routing", g.Name, "family"}, input: in, empty: true,
|
||||
hint: "agents can be shown only some families: magpie visible <agent> <family>",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), g.Name, tr("family")}, input: in, empty: true,
|
||||
hint: tr("agents can be shown only some families: magpie visible <agent> <family>"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Family = v; return nil }, g.Name+" family "+dash(v))
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Family = v; return nil }, trf("%s family %s", g.Name, dash(v)))
|
||||
}})
|
||||
m.back = modeGroup
|
||||
case "N":
|
||||
in := newInput("your own word on it, e.g. office key only")
|
||||
in := newInput(tr("your own word on it, e.g. office key only"))
|
||||
in.SetValue(g.Note)
|
||||
m.openAsk(ask{crumbs: []string{"routing", g.Name, "note"}, input: in, empty: true,
|
||||
hint: "shown under its name; empty clears it",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), g.Name, tr("note")}, input: in, empty: true,
|
||||
hint: tr("shown under its name; empty clears it"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Note = v; return nil }, g.Name+" note "+dash(provider.CleanNote(v)))
|
||||
return saveGroup(g.ID, func(g *provider.Group) error { g.Note = v; return nil }, trf("%s note %s", g.Name, dash(provider.CleanNote(v))))
|
||||
}})
|
||||
m.back = modeGroup
|
||||
case "x":
|
||||
in := newInput("tokens, e.g. 200k · empty for its models' own")
|
||||
in := newInput(tr("tokens, e.g. 200k · empty for its models' own"))
|
||||
if g.Context > 0 {
|
||||
in.SetValue(fmt.Sprint(g.Context))
|
||||
}
|
||||
m.openAsk(ask{crumbs: []string{"routing", g.Name, "context"}, input: in, empty: true,
|
||||
hint: "how long a request agents are told the group takes, rather than its largest model's",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), g.Name, tr("context")}, input: in, empty: true,
|
||||
hint: tr("how long a request agents are told the group takes, rather than its largest model's"),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveGroup(g.ID, func(g *provider.Group) error {
|
||||
if v == "" {
|
||||
@@ -520,28 +520,28 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
n, err := provider.ParseTokens(v)
|
||||
g.Context = n
|
||||
return err
|
||||
}, g.Name+" context "+dash(v))
|
||||
}, trf("%s context %s", g.Name, dash(v)))
|
||||
}})
|
||||
m.back = modeGroup
|
||||
case "l":
|
||||
in := newInput("e.g. low,medium,high,xhigh · empty for those its models share")
|
||||
in := newInput(tr("e.g. low,medium,high,xhigh · empty for those its models share"))
|
||||
in.SetValue(strings.Join(g.Levels, ","))
|
||||
m.openAsk(ask{crumbs: []string{"routing", g.Name, "levels"}, input: in, empty: true,
|
||||
hint: "the reasoning levels agents are offered: " + strings.Join(provider.Levels, ", ") + "; a model without the one asked is sent its nearest",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), g.Name, tr("levels")}, input: in, empty: true,
|
||||
hint: trf("the reasoning levels agents are offered: %s; a model without the one asked is sent its nearest", strings.Join(provider.Levels, ", ")),
|
||||
onEnter: func(v string) tea.Cmd {
|
||||
return saveGroup(g.ID, func(g *provider.Group) error {
|
||||
var err error
|
||||
g.Levels, err = provider.CleanLevels(strings.FieldsFunc(v, func(r rune) bool { return r == ',' || r == ' ' }))
|
||||
return err
|
||||
}, g.Name+" levels "+dash(v))
|
||||
}, trf("%s levels %s", g.Name, dash(v)))
|
||||
}})
|
||||
m.back = modeGroup
|
||||
case "R":
|
||||
in := newInput("the group's new id")
|
||||
in := newInput(tr("the group's new id"))
|
||||
in.SetValue(g.ID)
|
||||
in.CursorEnd()
|
||||
m.openAsk(ask{crumbs: []string{"routing", g.Name, "rename"}, input: in,
|
||||
hint: "agents pick it as group/<id>: those on it, and the groups that have it in them, follow",
|
||||
m.openAsk(ask{crumbs: []string{tr("routing"), g.Name, tr("rename")}, input: in,
|
||||
hint: tr("agents pick it as group/<id>: those on it, and the groups that have it in them, follow"),
|
||||
onEnter: func(to string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if _, err := agent.RenameGroup(g.ID, to); err != nil {
|
||||
@@ -556,7 +556,7 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
i := m.gsel - n
|
||||
if m.confirm != fmt.Sprintf("rule/%d", i) {
|
||||
m.confirm = fmt.Sprintf("rule/%d", i)
|
||||
m.flash, m.flashOK = fmt.Sprintf("press d again to remove rule %d", i+1), false
|
||||
m.flash, m.flashOK = trf("press d again to remove rule %d", i+1), false
|
||||
return m, nil
|
||||
}
|
||||
m.confirm = ""
|
||||
@@ -564,21 +564,21 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, saveGroup(g.ID, func(g *provider.Group) error {
|
||||
g.Rules = slices.Delete(g.Rules, i, i+1)
|
||||
return nil
|
||||
}, fmt.Sprintf("rule %d removed", i+1))
|
||||
}, trf("rule %d removed", i+1))
|
||||
}
|
||||
if n == 0 {
|
||||
return m, nil
|
||||
}
|
||||
id := g.Members[m.gsel]
|
||||
if n == 1 {
|
||||
m.flash, m.flashOK = "a group needs a model in it · d on the routing list removes the group", false
|
||||
m.flash, m.flashOK = tr("a group needs a model in it · d on the routing list removes the group"), false
|
||||
return m, nil
|
||||
}
|
||||
if m.confirm != "member/"+id {
|
||||
m.confirm = "member/" + id
|
||||
m.flash, m.flashOK = "press d again to take "+id+" out", false
|
||||
m.flash, m.flashOK = trf("press d again to take %s out", id), false
|
||||
if slices.ContainsFunc(g.Rules, func(r provider.Rule) bool { _, kept := r.Without(id); return !kept }) {
|
||||
m.flash += " and its rules"
|
||||
m.flash += tr(" and its rules")
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -595,7 +595,7 @@ func (m model) updateGroup(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
g.Rules = rules
|
||||
return nil
|
||||
}, id+" taken out")
|
||||
}, trf("%s taken out", id))
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
@@ -615,7 +615,7 @@ func (m model) viewGroups() string {
|
||||
b.WriteString(m.header())
|
||||
b.WriteString("\n\n")
|
||||
if len(m.groups) == 0 {
|
||||
b.WriteString(pad + " " + sMuted.Render("no routing groups yet · n makes one"))
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("no routing groups yet · n makes one")))
|
||||
return b.String()
|
||||
}
|
||||
nameW, idW := 0, 0
|
||||
@@ -630,7 +630,7 @@ func (m model) viewGroups() string {
|
||||
for i := start; i < min(len(m.groups), start+visible); i++ {
|
||||
g := m.groups[i]
|
||||
if i == m.shown {
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render("removed · found by magpie, taken away: u brings one back") + "\n")
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render(tr("removed · found by magpie, taken away: u brings one back")) + "\n")
|
||||
}
|
||||
marker, name := " ", sName.Render(padRight(dash(g.Name), nameW))
|
||||
if g.Hidden {
|
||||
@@ -645,25 +645,25 @@ func (m model) viewGroups() string {
|
||||
continue
|
||||
}
|
||||
listed, off := m.listedMembers(g)
|
||||
notes := []string{fmt.Sprintf("%d model%s", len(listed), plural(len(listed))), groupRouting(g)}
|
||||
notes := []string{trf("%d model%s", len(listed), plural(len(listed))), groupRouting(g)}
|
||||
if off > 0 {
|
||||
notes = append(notes, fmt.Sprintf("%d switched off", off))
|
||||
notes = append(notes, trf("%d switched off", off))
|
||||
}
|
||||
if g.Affinity != "" {
|
||||
notes = append(notes, staysName(g.Affinity))
|
||||
}
|
||||
if len(g.Rules) > 0 {
|
||||
notes = append(notes, fmt.Sprintf("%d rule%s", len(g.Rules), plural(len(g.Rules))))
|
||||
notes = append(notes, trf("%d rule%s", len(g.Rules), plural(len(g.Rules))))
|
||||
}
|
||||
if g.Family != "" {
|
||||
notes = append(notes, "family "+g.Family)
|
||||
notes = append(notes, trf("family %s", g.Family))
|
||||
}
|
||||
if g.Auto {
|
||||
notes = append(notes, "found")
|
||||
notes = append(notes, tr("found"))
|
||||
}
|
||||
members := strings.Join(listed, " → ")
|
||||
if len(g.Match) > 0 {
|
||||
notes = append(notes, fmt.Sprintf("%d pattern%s", len(g.Match), plural(len(g.Match))))
|
||||
notes = append(notes, trf("%d pattern%s", len(g.Match), plural(len(g.Match))))
|
||||
}
|
||||
line += " " + sText.Render(strings.Join(notes, " · "))
|
||||
if room := m.w - lipgloss.Width(line) - 4; room > 10 {
|
||||
@@ -677,27 +677,27 @@ func (m model) viewGroups() string {
|
||||
func (m model) viewGroup() string {
|
||||
g, _ := m.group()
|
||||
var b strings.Builder
|
||||
b.WriteString(m.header("routing", g.Name))
|
||||
b.WriteString(m.header(tr("routing"), g.Name))
|
||||
b.WriteString("\n\n")
|
||||
head := []string{g.Ref(), groupRouting(g), staysName(g.Affinity)}
|
||||
if g.Context > 0 {
|
||||
head = append(head, "context "+fmtTokens(g.Context))
|
||||
head = append(head, trf("context %s", fmtTokens(g.Context)))
|
||||
}
|
||||
if len(g.Levels) > 0 {
|
||||
head = append(head, "levels "+strings.Join(g.Levels, "/"))
|
||||
head = append(head, trf("levels %s", strings.Join(g.Levels, "/")))
|
||||
}
|
||||
if g.Family != "" {
|
||||
head = append(head, "family "+g.Family)
|
||||
head = append(head, trf("family %s", g.Family))
|
||||
}
|
||||
if g.Auto {
|
||||
head = append(head, "found by magpie: a change makes it yours")
|
||||
head = append(head, tr("found by magpie: a change makes it yours"))
|
||||
}
|
||||
b.WriteString(pad + " " + sMuted.Render(strings.Join(head, " · ")) + "\n")
|
||||
if g.Note != "" {
|
||||
b.WriteString(pad + " " + sText.Render(trunc(g.Note, max(m.w-8, 10))) + "\n")
|
||||
}
|
||||
b.WriteString("\n")
|
||||
b.WriteString(pad + " " + sFaint.Render("models · the first that can take a request gets it") + "\n")
|
||||
b.WriteString(pad + " " + sFaint.Render(tr("models · the first that can take a request gets it")) + "\n")
|
||||
hits := provider.PatternHits(g)
|
||||
memFrom, memTo, ruleFrom, ruleTo := groupWindow(len(g.Members), len(g.Rules), m.gsel, m.groupRows(g, len(hits)))
|
||||
for i := memFrom; i < memTo; i++ {
|
||||
@@ -707,31 +707,31 @@ func (m model) viewGroup() string {
|
||||
marker, name = sCursor.Render("▸ "), sNameOn.Render(id)
|
||||
}
|
||||
if g.IsFast(id) {
|
||||
name += sMuted.Render(" · fast")
|
||||
name += sMuted.Render(" · " + tr("fast"))
|
||||
}
|
||||
if slices.Contains(g.Matched, id) {
|
||||
name += sMuted.Render(" · by pattern")
|
||||
name += sMuted.Render(" · " + tr("by pattern"))
|
||||
}
|
||||
if m.memberOff(id) {
|
||||
name += sMuted.Render(" · switched off: skipped until it is on again")
|
||||
name += sMuted.Render(" · " + tr("switched off: skipped until it is on again"))
|
||||
}
|
||||
b.WriteString(pad + marker + sFaint.Render(fmt.Sprintf("%d ", i+1)) + name + "\n")
|
||||
}
|
||||
// patterns find models in the catalog each time (#766): how many now,
|
||||
// and one that finds none said so rather than left an empty list
|
||||
if len(hits) > 0 {
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render("patterns · every model they match now, after those named") + "\n")
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render(tr("patterns · every model they match now, after those named")) + "\n")
|
||||
for _, h := range hits {
|
||||
n := sMuted.Render(fmt.Sprintf(" · %d model%s", h.Models, plural(h.Models)))
|
||||
n := sMuted.Render(" · " + trf("%d model%s", h.Models, plural(h.Models)))
|
||||
if h.Models == 0 {
|
||||
n = sBad.Render(" · matches nothing now")
|
||||
n = sBad.Render(" · " + tr("matches nothing now"))
|
||||
}
|
||||
b.WriteString(pad + " " + sText.Render(h.Pattern) + n + "\n")
|
||||
}
|
||||
}
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render("rules · as a turn begins, the first that matches sends it to its model first; a pause leaves its model out while it holds") + "\n")
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render(tr("rules · as a turn begins, the first that matches sends it to its model first; a pause leaves its model out while it holds")) + "\n")
|
||||
if len(g.Rules) == 0 {
|
||||
b.WriteString(pad + " " + sMuted.Render("none · n adds one") + "\n")
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("none · n adds one")) + "\n")
|
||||
}
|
||||
for i := ruleFrom; i < ruleTo; i++ {
|
||||
r := g.Rules[i]
|
||||
@@ -742,15 +742,15 @@ func (m model) viewGroup() string {
|
||||
}
|
||||
arrow := " → "
|
||||
if r.Pause {
|
||||
arrow = " → pause "
|
||||
arrow = " → " + tr("pause") + " "
|
||||
}
|
||||
if r.UseEffort != "" {
|
||||
use += sMuted.Render(" at ") + sText.Render(r.UseEffort)
|
||||
use += sMuted.Render(" "+tr("at")+" ") + sText.Render(r.UseEffort)
|
||||
}
|
||||
b.WriteString(pad + marker + sFaint.Render(fmt.Sprintf("%d ", i+1)) + sMuted.Render(strings.Join(r.Conditions(), " · ")+arrow) + use + "\n")
|
||||
}
|
||||
if slices.ContainsFunc(g.Rules, func(r provider.Rule) bool { return r.Intent != "" }) {
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render("classifier ") + sText.Render(dash(g.Classifier)) + sFaint.Render(" · tells which intent a message is") + "\n")
|
||||
b.WriteString("\n" + pad + " " + sFaint.Render(tr("classifier")+" ") + sText.Render(dash(g.Classifier)) + sFaint.Render(" · "+tr("tells which intent a message is")) + "\n")
|
||||
}
|
||||
return strings.TrimRight(b.String(), "\n")
|
||||
}
|
||||
|
||||
+44
-44
@@ -61,9 +61,9 @@ func (m model) sessShown() []sessions.Session {
|
||||
// agent (RustCats on X), magpie reads no agent's sessions, and says how.
|
||||
func sessNothing() string {
|
||||
if !sessions.SettleReads().Asked {
|
||||
return "magpie reads no agent's session history until you allow it · magpie sessions read on all (or on <agent>), or the app's Sessions page"
|
||||
return tr("magpie reads no agent's session history until you allow it · magpie sessions read on all (or on <agent>), or the app's Sessions page")
|
||||
}
|
||||
return "nothing in this range · Claude Code's, Codex's, OpenCode's and Pi's sessions on this computer show up here"
|
||||
return tr("nothing in this range · Claude Code's, Codex's, OpenCode's and Pi's sessions on this computer show up here")
|
||||
}
|
||||
|
||||
func sessFilter(all []sessions.Session, days int, model, folder string, now time.Time) []sessions.Session {
|
||||
@@ -143,11 +143,11 @@ func (m model) updateSessions(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
// page back when the agent quits.
|
||||
func resumeSession(s sessions.Session) tea.Cmd {
|
||||
if s.Resume == "" {
|
||||
return func() tea.Msg { return flashMsg{text: "this session can't be resumed from here"} }
|
||||
return func() tea.Msg { return flashMsg{text: tr("this session can't be resumed from here")} }
|
||||
}
|
||||
// the shell's own "no such directory" is gone with the screen it was on
|
||||
if fi, err := os.Stat(s.Cwd); s.Cwd != "" && (err != nil || !fi.IsDir()) {
|
||||
return func() tea.Msg { return flashMsg{text: "its folder " + tildePath(s.Cwd) + " isn't there any more"} }
|
||||
return func() tea.Msg { return flashMsg{text: trf("its folder %s isn't there any more", tildePath(s.Cwd))} }
|
||||
}
|
||||
run := sessions.ResumeNow(s)
|
||||
c := proc.Command("sh", "-c", run)
|
||||
@@ -156,9 +156,9 @@ func resumeSession(s sessions.Session) tea.Cmd {
|
||||
}
|
||||
return tea.ExecProcess(c, func(err error) tea.Msg {
|
||||
if err != nil {
|
||||
return flashMsg{text: "resume: " + err.Error()}
|
||||
return flashMsg{text: trf("resume: %s", err.Error())}
|
||||
}
|
||||
return flashMsg{text: "back from the session", ok: true}
|
||||
return flashMsg{text: tr("back from the session"), ok: true}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -166,19 +166,19 @@ func resumeSession(s sessions.Session) tea.Cmd {
|
||||
// the other filter.
|
||||
func (m *model) openSessPick(folder bool) {
|
||||
r := m.sstats.Sum(m.smodel, m.sfolder)
|
||||
all, shares, crumb := allModels, r.Models, "model"
|
||||
all, shares, crumb := tr(allModels), r.Models, tr("model")
|
||||
if folder {
|
||||
all, shares, crumb = allFolders, r.Folders, "folder"
|
||||
all, shares, crumb = tr(allFolders), r.Folders, tr("folder")
|
||||
}
|
||||
items := []agent.Option{{Value: all}}
|
||||
for _, s := range shares {
|
||||
if s.Name != "" {
|
||||
items = append(items, agent.Option{Value: s.Name, Note: fmtTokens(s.Spent()) + " tokens"})
|
||||
items = append(items, agent.Option{Value: s.Name, Note: trf("%s tokens", fmtTokens(s.Spent()))})
|
||||
}
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: []string{"sessions", crumb},
|
||||
input: newInput("filter"),
|
||||
crumbs: []string{tr("sessions"), crumb},
|
||||
input: newInput(tr("filter")),
|
||||
items: items,
|
||||
onPick: func(v string) tea.Cmd {
|
||||
if v == all {
|
||||
@@ -210,20 +210,20 @@ func sessBar(rng int, model, folder string, stats bool) string {
|
||||
var tabs []string
|
||||
for i, r := range sessRanges {
|
||||
if i == rng {
|
||||
tabs = append(tabs, sPill.Render(r.name))
|
||||
tabs = append(tabs, sPill.Render(tr(r.name)))
|
||||
} else {
|
||||
tabs = append(tabs, sMuted.Render(" "+r.name+" "))
|
||||
tabs = append(tabs, sMuted.Render(" "+tr(r.name)+" "))
|
||||
}
|
||||
}
|
||||
filter := func(v, all string) string {
|
||||
if v == "" {
|
||||
return sMuted.Render(all)
|
||||
return sMuted.Render(tr(all))
|
||||
}
|
||||
return sNameOn.Render(v)
|
||||
}
|
||||
view := sNameOn.Render("sessions") + sFaint.Render(" · stats")
|
||||
view := sNameOn.Render(tr("sessions")) + sFaint.Render(" · "+tr("stats"))
|
||||
if stats {
|
||||
view = sFaint.Render("sessions · ") + sNameOn.Render("stats")
|
||||
view = sFaint.Render(tr("sessions")+" · ") + sNameOn.Render(tr("stats"))
|
||||
}
|
||||
return strings.Join(tabs, " ") + " " + filter(model, allModels) + sFaint.Render(" · ") + filter(tildePath(folder), allFolders) + " " + view
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func sessListLines(list []sessions.Session, agents []*agent.Agent, rng int, mode
|
||||
add("")
|
||||
if len(list) == 0 {
|
||||
if model != "" || folder != "" {
|
||||
add(sMuted.Render("no session matches · x clears the filters"))
|
||||
add(sMuted.Render(tr("no session matches · x clears the filters")))
|
||||
} else {
|
||||
add(sMuted.Render(sessNothing()))
|
||||
}
|
||||
@@ -256,7 +256,7 @@ func sessListLines(list []sessions.Session, agents []*agent.Agent, rng int, mode
|
||||
if s.Cost > 0 {
|
||||
c = sOK.Render(fmtCost(usage.Totals{Cost: s.Cost, Unpriced: s.Unpriced}))
|
||||
} else if s.Spent() > 0 {
|
||||
c = sFaint.Render("no price")
|
||||
c = sFaint.Render(tr("no price"))
|
||||
}
|
||||
where := filepath.Base(s.Cwd)
|
||||
if s.Cwd == "" {
|
||||
@@ -264,10 +264,10 @@ func sessListLines(list []sessions.Session, agents []*agent.Agent, rng int, mode
|
||||
}
|
||||
title := strings.Join(strings.Fields(s.Title), " ")
|
||||
if title == "" {
|
||||
title = "(untitled)"
|
||||
title = tr("(untitled)")
|
||||
}
|
||||
rows[i] = row{sessAgo(s.Last, now), cmp.Or(names[s.Agent], s.Agent), trunc(where, 24), fmtTokens(s.Spent()), c, title}
|
||||
wn, ww, wf, wt = max(wn, len(rows[i].when)), max(ww, lipgloss.Width(rows[i].who)), max(wf, lipgloss.Width(rows[i].where)), max(wt, len(rows[i].tokens))
|
||||
wn, ww, wf, wt = max(wn, lipgloss.Width(rows[i].when)), max(ww, lipgloss.Width(rows[i].who)), max(wf, lipgloss.Width(rows[i].where)), max(wt, lipgloss.Width(rows[i].tokens))
|
||||
}
|
||||
visible := max(3, height-11) // the header, the bar, the arrows, the command and the footer around them
|
||||
start := 0
|
||||
@@ -276,7 +276,7 @@ func sessListLines(list []sessions.Session, agents []*agent.Agent, rng int, mode
|
||||
}
|
||||
start = max(0, min(start, len(list)-visible))
|
||||
if start > 0 {
|
||||
add(sFaint.Render(fmt.Sprintf("↑ %d more", start)))
|
||||
add(sFaint.Render(trf("↑ %d more", start)))
|
||||
}
|
||||
for i := start; i < len(list) && i < start+visible; i++ {
|
||||
r := rows[i]
|
||||
@@ -291,11 +291,11 @@ func sessListLines(list []sessions.Session, agents []*agent.Agent, rng int, mode
|
||||
out = append(out, pad+line)
|
||||
}
|
||||
if rest := len(list) - start - visible; rest > 0 {
|
||||
add(sFaint.Render(fmt.Sprintf("↓ %d more", rest)))
|
||||
add(sFaint.Render(trf("↓ %d more", rest)))
|
||||
}
|
||||
if sel < len(list) && list[sel].Resume != "" {
|
||||
add("")
|
||||
add(sFaint.Render(trunc("↵ runs "+list[sel].Resume, max(20, width-2))))
|
||||
add(sFaint.Render(trunc(trf("↵ runs %s", list[sel].Resume), max(20, width-2))))
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -305,13 +305,13 @@ func sessAgo(t, now time.Time) string {
|
||||
d := now.Sub(t)
|
||||
switch {
|
||||
case d < time.Minute:
|
||||
return "just now"
|
||||
return tr("just now")
|
||||
case d < time.Hour:
|
||||
return fmt.Sprintf("%dm ago", int(d.Minutes()))
|
||||
return trf("%dm ago", int(d.Minutes()))
|
||||
case d < 48*time.Hour:
|
||||
return fmt.Sprintf("%dh ago", int(d.Hours()))
|
||||
return trf("%dh ago", int(d.Hours()))
|
||||
case d < 60*24*time.Hour:
|
||||
return fmt.Sprintf("%dd ago", int(d.Hours()/24))
|
||||
return trf("%dd ago", int(d.Hours()/24))
|
||||
}
|
||||
return t.In(time.Local).Format("2006-01-02")
|
||||
}
|
||||
@@ -327,13 +327,13 @@ func sessLines(st sessions.Stats, rng int, model, folder string, byCost bool, wi
|
||||
r := st.Sum(model, folder)
|
||||
if r.Spent() == 0 && r.CacheRead == 0 {
|
||||
if model != "" || folder != "" {
|
||||
add(sMuted.Render("no session matches · x clears the filters"))
|
||||
add(sMuted.Render(tr("no session matches · x clears the filters")))
|
||||
} else {
|
||||
add(sMuted.Render(sessNothing()))
|
||||
}
|
||||
return out
|
||||
}
|
||||
c := sFaint.Render("no price")
|
||||
c := sFaint.Render(tr("no price"))
|
||||
if r.Cost > 0 {
|
||||
c = sOK.Render(fmtCost(usage.Totals{Cost: r.Cost, Unpriced: len(r.Unpriced)}))
|
||||
}
|
||||
@@ -341,16 +341,16 @@ func sessLines(st sessions.Stats, rng int, model, folder string, byCost bool, wi
|
||||
// of all the prompts came to: Input leaves out what was read from the
|
||||
// cache and what was written to it
|
||||
if p := r.Input + r.CacheRead + r.CacheWrite; r.CacheRead > 0 && p > 0 {
|
||||
hit = sMuted.Render(" (" + usage.HitPct(float64(r.CacheRead)/float64(p)) + " hit)")
|
||||
hit = sMuted.Render(" " + trf("(%s hit)", usage.HitPct(float64(r.CacheRead)/float64(p))))
|
||||
}
|
||||
active := sessions.Duration(r.Active)
|
||||
if r.Active >= 0 {
|
||||
active += sMuted.Render(fmt.Sprintf(" on %d day%s", r.DaysUsed, plural(r.DaysUsed)))
|
||||
active += sMuted.Render(" " + trf("on %d day%s", r.DaysUsed, plural(r.DaysUsed)))
|
||||
} else {
|
||||
active += sMuted.Render(" not kept by model")
|
||||
active += sMuted.Render(" " + tr("not kept by model"))
|
||||
}
|
||||
add(sName.Render(fmtTokens(r.Spent())+" tokens") + sMuted.Render(" · ") + c + sMuted.Render(" · cache read ") + sText.Render(fmtTokens(r.CacheRead)) + hit + sMuted.Render(" · active ") + sText.Render(active))
|
||||
add(sMuted.Render("in " + fmtTokens(r.Input) + " out " + fmtTokens(r.Output) + " cache write " + fmtTokens(r.CacheWrite)))
|
||||
add(sName.Render(trf("%s tokens", fmtTokens(r.Spent()))) + sMuted.Render(" · ") + c + sMuted.Render(" · "+tr("cache read")+" ") + sText.Render(fmtTokens(r.CacheRead)) + hit + sMuted.Render(" · "+tr("active")+" ") + sText.Render(active))
|
||||
add(sMuted.Render(trf("in %s out %s cache write %s", fmtTokens(r.Input), fmtTokens(r.Output), fmtTokens(r.CacheWrite))))
|
||||
add("")
|
||||
|
||||
chart := sessChart(r.Days, byCost, width, 6)
|
||||
@@ -366,7 +366,7 @@ func sessLines(st sessions.Stats, rng int, model, folder string, byCost bool, wi
|
||||
if len(ss) == 0 {
|
||||
return
|
||||
}
|
||||
add(sFaint.Render(head))
|
||||
add(sFaint.Render(tr(head)))
|
||||
w := 0
|
||||
for _, s := range ss[:min(len(ss), room)] {
|
||||
w = max(w, lipgloss.Width(name(s.Name)))
|
||||
@@ -377,10 +377,10 @@ func sessLines(st sessions.Stats, rng int, model, folder string, byCost bool, wi
|
||||
}
|
||||
for i, s := range ss {
|
||||
if i == room {
|
||||
add(sFaint.Render(fmt.Sprintf("and %d more · f and M pick one", len(ss)-room)))
|
||||
add(sFaint.Render(trf("and %d more · f and M pick one", len(ss)-room)))
|
||||
break
|
||||
}
|
||||
sc := sFaint.Render("no price")
|
||||
sc := sFaint.Render(tr("no price"))
|
||||
if s.Cost > 0 {
|
||||
sc = sOK.Render(fmtCost(usage.Totals{Cost: s.Cost}))
|
||||
}
|
||||
@@ -394,7 +394,7 @@ func sessLines(st sessions.Stats, rng int, model, folder string, byCost bool, wi
|
||||
if folder == "" {
|
||||
table("folders", r.Folders, func(s string) string {
|
||||
if s == "" {
|
||||
return "(no folder)"
|
||||
return tr("(no folder)")
|
||||
}
|
||||
return trunc(tildePath(s), 48)
|
||||
})
|
||||
@@ -469,17 +469,17 @@ func sessChart(days []sessions.DayTotal, byCost bool, width, height int) []strin
|
||||
top = fmtCost(usage.Totals{Cost: peak})
|
||||
}
|
||||
lines[0] += " " + sFaint.Render(top)
|
||||
unit := "a day"
|
||||
unit := tr("a day")
|
||||
if step == 7 {
|
||||
unit = "a week"
|
||||
unit = tr("a week")
|
||||
} else if step > 1 {
|
||||
unit = fmt.Sprintf("%d days", step)
|
||||
unit = trf("%d days", step)
|
||||
}
|
||||
lines[height-1] += " " + sFaint.Render(map[bool]string{false: "tokens", true: "cost"}[byCost]+" · "+unit)
|
||||
lines[height-1] += " " + sFaint.Render(tr(map[bool]string{false: "tokens", true: "cost"}[byCost])+" · "+unit)
|
||||
span := len(bs) + (len(bs)-1)*len(gap)
|
||||
first, last := shortDate(bs[0].date), shortDate(bs[len(bs)-1].date)
|
||||
under := first
|
||||
if n := span - len(first) - len(last); n > 0 {
|
||||
if n := span - lipgloss.Width(first) - lipgloss.Width(last); n > 0 {
|
||||
under += strings.Repeat(" ", n) + last
|
||||
}
|
||||
return append(lines, sFaint.Render(under))
|
||||
@@ -490,7 +490,7 @@ func shortDate(d string) string {
|
||||
if err != nil {
|
||||
return d
|
||||
}
|
||||
return t.Format("Jan 2")
|
||||
return t.Format(tr("Jan 2"))
|
||||
}
|
||||
|
||||
func tildePath(p string) string {
|
||||
|
||||
+40
-36
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/yetone/magpie/internal/provider"
|
||||
"github.com/yetone/magpie/internal/sessions"
|
||||
"github.com/yetone/magpie/internal/settings"
|
||||
"github.com/yetone/magpie/internal/uilang"
|
||||
"github.com/yetone/magpie/internal/usage"
|
||||
)
|
||||
|
||||
@@ -159,12 +160,13 @@ type syncedMsg struct{ err error }
|
||||
// and a signal then is the caller's to handle, as bubbletea starts
|
||||
// listening only as the program runs.
|
||||
func Run(ready func()) error {
|
||||
lang = speak(uilang.Pick(settings.Load().Lang, uilang.System))
|
||||
m := newModel()
|
||||
if ready != nil {
|
||||
ready()
|
||||
}
|
||||
if len(m.agents) == 0 {
|
||||
return fmt.Errorf("no supported agents found on this machine")
|
||||
return fmt.Errorf("%s", tr("no supported agents found on this machine"))
|
||||
}
|
||||
ctx, stop := context.WithCancel(context.Background())
|
||||
wait := serveGateway(ctx)
|
||||
@@ -304,7 +306,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
case balanceMsg:
|
||||
m.bal = msg
|
||||
if m.flash == "asking the vendors for balances…" {
|
||||
if m.flash == tr("asking the vendors for balances…") {
|
||||
m.flash = ""
|
||||
}
|
||||
return m, nil
|
||||
@@ -339,7 +341,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
if m.gid == msg.from {
|
||||
m.gid = msg.to
|
||||
}
|
||||
m.flash, m.flashOK = "group/"+msg.from+" is group/"+msg.to+" now", true
|
||||
m.flash, m.flashOK = trf("group/%s is group/%s now", msg.from, msg.to), true
|
||||
m.reload()
|
||||
return m, nil
|
||||
case editedMsg:
|
||||
@@ -358,9 +360,9 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
m.syncing = false
|
||||
m.modelsChanged()
|
||||
if msg.err != nil {
|
||||
m.flash, m.flashOK = "catalog sync failed: "+msg.err.Error(), false
|
||||
m.flash, m.flashOK = trf("catalog sync failed: %s", msg.err.Error()), false
|
||||
} else {
|
||||
m.flash, m.flashOK = "model catalog synced from models.dev", true
|
||||
m.flash, m.flashOK = tr("model catalog synced from models.dev"), true
|
||||
}
|
||||
return m, nil
|
||||
case tea.KeyMsg:
|
||||
@@ -380,7 +382,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
if msg.String() == "r" {
|
||||
m.reload()
|
||||
m.flash, m.flashOK = "reloaded", true
|
||||
m.flash, m.flashOK = tr("reloaded"), true
|
||||
if m.page == pageUsage {
|
||||
m.quotas = nil
|
||||
// every account read again, a saved Claude
|
||||
@@ -458,7 +460,7 @@ func (m model) updateList(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
m.openFieldPicker()
|
||||
case "r":
|
||||
m.reload()
|
||||
m.flash, m.flashOK = "reloaded", true
|
||||
m.flash, m.flashOK = tr("reloaded"), true
|
||||
case "S":
|
||||
if !m.syncing {
|
||||
m.syncing = true
|
||||
@@ -466,7 +468,7 @@ func (m model) updateList(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
}
|
||||
case "s":
|
||||
m.mode, m.rename = modeName, ""
|
||||
m.name = newInput("profile name")
|
||||
m.name = newInput(tr("profile name"))
|
||||
case "p":
|
||||
m.openProfiles()
|
||||
}
|
||||
@@ -480,14 +482,14 @@ func (m *model) openFieldPicker() {
|
||||
items := a.Picks(f, m.values[m.row])
|
||||
items = withCurrent(items, cur)
|
||||
set := f.Set
|
||||
label := a.Name + " · " + f.Label
|
||||
label := a.Name + " · " + tr(f.Label)
|
||||
m.pk = picker{
|
||||
crumbs: []string{a.Name, f.Label},
|
||||
input: newInput("type to filter, or enter a custom value"),
|
||||
crumbs: []string{a.Name, tr(f.Label)},
|
||||
input: newInput(tr("type to filter, or enter a custom value")),
|
||||
items: items,
|
||||
relist: func() []agent.Option { return withCurrent(a.Picks(f, a.Values()), f.Get()) },
|
||||
custom: true,
|
||||
empty: "no models known yet, type one",
|
||||
empty: tr("no models known yet, type one"),
|
||||
onPick: func(v string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
if err := set(v); err != nil {
|
||||
@@ -513,15 +515,15 @@ func (m *model) openProfiles() {
|
||||
for _, n := range profile.Names(ps) {
|
||||
note := profile.LongSummary(ps[n])
|
||||
if profile.InUse(ps[n], detected, nil) {
|
||||
note = strings.TrimSuffix("in use · "+note, " · ")
|
||||
note = strings.TrimSuffix(tr("in use")+" · "+note, " · ")
|
||||
}
|
||||
items = append(items, agent.Option{Value: n, Note: note})
|
||||
}
|
||||
m.pk = picker{
|
||||
crumbs: []string{"profiles"},
|
||||
input: newInput("filter profiles"),
|
||||
crumbs: []string{tr("profiles")},
|
||||
input: newInput(tr("filter profiles")),
|
||||
items: items,
|
||||
empty: "no profiles yet · press s in the list to save one",
|
||||
empty: tr("no profiles yet · press s in the list to save one"),
|
||||
onPick: func(n string) tea.Cmd {
|
||||
return func() tea.Msg {
|
||||
ps, err := profile.Load()
|
||||
@@ -532,7 +534,7 @@ func (m *model) openProfiles() {
|
||||
if err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
text := fmt.Sprintf("profile %s applied · %d change%s", n, a.Changed, plural(a.Changed))
|
||||
text := trf("profile %s applied · %d change%s", n, a.Changed, plural(a.Changed))
|
||||
for _, line := range profile.Report(a) {
|
||||
text += " · " + line
|
||||
}
|
||||
@@ -544,7 +546,7 @@ func (m *model) openProfiles() {
|
||||
if err := profile.Delete(n); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "profile " + n + " deleted", ok: true}
|
||||
return flashMsg{text: trf("profile %s deleted", n), ok: true}
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -571,7 +573,7 @@ func (m model) updatePicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
return m, nil
|
||||
case "ctrl+r":
|
||||
if m.pk.refetch != nil {
|
||||
m.flash, m.flashOK = "asking for the models again…", true
|
||||
m.flash, m.flashOK = tr("asking for the models again…"), true
|
||||
return m, m.pk.refetch()
|
||||
}
|
||||
return m, nil
|
||||
@@ -579,7 +581,7 @@ func (m model) updatePicker(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
// the profile picked, renamed on a line holding its name (#2721)
|
||||
if m.mode == modeProfiles && len(m.pk.match) > 0 {
|
||||
m.rename = m.pk.items[m.pk.match[m.pk.cursor]].Value
|
||||
m.name = newInput("new name")
|
||||
m.name = newInput(tr("new name"))
|
||||
m.name.SetValue(m.rename)
|
||||
m.mode = modeName
|
||||
}
|
||||
@@ -633,7 +635,7 @@ func (m model) updateName(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if err := profile.Rename(old, n); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "profile " + old + " renamed to " + n, ok: true}
|
||||
return flashMsg{text: trf("profile %s renamed to %s", old, n), ok: true}
|
||||
}
|
||||
}
|
||||
return m, func() tea.Msg {
|
||||
@@ -644,7 +646,7 @@ func (m model) updateName(msg tea.KeyMsg) (tea.Model, tea.Cmd) {
|
||||
if err := profile.Save(n, p); err != nil {
|
||||
return flashMsg{text: err.Error()}
|
||||
}
|
||||
return flashMsg{text: "saved profile " + n, ok: true}
|
||||
return flashMsg{text: trf("saved profile %s", n), ok: true}
|
||||
}
|
||||
}
|
||||
var cmd tea.Cmd
|
||||
@@ -672,10 +674,10 @@ func withCurrent(items []agent.Option, cur string) []agent.Option {
|
||||
var out []agent.Option
|
||||
if cur != "" {
|
||||
seen[cur] = true
|
||||
note := "current"
|
||||
note := tr("current")
|
||||
for _, it := range items {
|
||||
if it.Value == cur && it.Note != "" {
|
||||
note = it.Note + " · current"
|
||||
note = it.Note + " · " + tr("current")
|
||||
}
|
||||
}
|
||||
out = append(out, agent.Option{Value: cur, Note: note})
|
||||
@@ -767,8 +769,10 @@ func clamp(i, n int) int {
|
||||
return i
|
||||
}
|
||||
|
||||
// plural is an English plural's "s"; a language without one (Chinese)
|
||||
// gets none.
|
||||
func plural(n int) string {
|
||||
if n == 1 {
|
||||
if n == 1 || lang != "en" {
|
||||
return ""
|
||||
}
|
||||
return "s"
|
||||
@@ -840,7 +844,7 @@ func (m model) View() string {
|
||||
case m.flash != "":
|
||||
status = sBad.Render("✗ ") + sText.Render(m.flash)
|
||||
case m.syncing:
|
||||
status = sMuted.Render("… syncing model catalog")
|
||||
status = sMuted.Render("… " + tr("syncing model catalog"))
|
||||
default:
|
||||
status = gatewayStatus()
|
||||
}
|
||||
@@ -859,7 +863,7 @@ func (m model) header(crumbs ...string) string {
|
||||
// the pages, this one marked
|
||||
s += " "
|
||||
for i, n := range pageNames {
|
||||
label := fmt.Sprintf("%d %s", i+1, n)
|
||||
label := fmt.Sprintf("%d %s", i+1, tr(n))
|
||||
if page(i) == m.page {
|
||||
s += sPill.Render(label) + " "
|
||||
} else {
|
||||
@@ -919,7 +923,7 @@ func (m model) viewList() string {
|
||||
cell = sValue.Render(v)
|
||||
}
|
||||
if j > 0 || f.Label != "model" {
|
||||
line += sMuted.Render(" " + f.Label)
|
||||
line += sMuted.Render(" " + tr(f.Label))
|
||||
}
|
||||
line += cell + " "
|
||||
}
|
||||
@@ -948,11 +952,11 @@ func (m model) viewPicker() string {
|
||||
|
||||
if len(p.match) == 0 {
|
||||
if v, ok := p.choice(); ok {
|
||||
b.WriteString(pad + " " + sMuted.Render("↵ use ") + sText.Render(v) + sMuted.Render(" as a custom value"))
|
||||
b.WriteString(pad + " " + sMuted.Render(trf("↵ use %s as a custom value", sText.Render(v))))
|
||||
} else if len(p.items) == 0 {
|
||||
b.WriteString(pad + " " + sMuted.Render(p.empty))
|
||||
} else {
|
||||
b.WriteString(pad + " " + sMuted.Render("no match"))
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("no match")))
|
||||
}
|
||||
return b.String()
|
||||
}
|
||||
@@ -993,22 +997,22 @@ func (m model) viewPicker() string {
|
||||
func (m model) viewName() string {
|
||||
var b strings.Builder
|
||||
if m.rename != "" {
|
||||
b.WriteString(m.header("rename profile") + "\n\n" + pad + sCursor.Render("❯ ") + m.name.View() + "\n\n")
|
||||
b.WriteString(pad + " " + sMuted.Render("renames "+m.rename+" · the settings it holds stay as they are"))
|
||||
b.WriteString(m.header(tr("rename profile")) + "\n\n" + pad + sCursor.Render("❯ ") + m.name.View() + "\n\n")
|
||||
b.WriteString(pad + " " + sMuted.Render(trf("renames %s · the settings it holds stay as they are", m.rename)))
|
||||
return b.String()
|
||||
}
|
||||
b.WriteString(m.header("save profile"))
|
||||
b.WriteString(m.header(tr("save profile")))
|
||||
b.WriteString("\n\n")
|
||||
b.WriteString(pad + sCursor.Render("❯ ") + m.name.View())
|
||||
b.WriteString("\n\n")
|
||||
b.WriteString(pad + " " + sMuted.Render("snapshots every agent's current settings"))
|
||||
b.WriteString(pad + " " + sMuted.Render(tr("snapshots every agent's current settings")))
|
||||
b.WriteString("\n\n")
|
||||
snap, _ := profile.Snapshot()
|
||||
for _, k := range sortedKeys(snap.Fields) {
|
||||
b.WriteString(pad + " " + sFaint.Render(padRight(k, 18)) + sText.Render(snap.Fields[k]) + "\n")
|
||||
}
|
||||
if snap.Library != nil {
|
||||
b.WriteString(pad + " " + sFaint.Render(padRight("library", 18)) + sText.Render(strings.TrimPrefix(snap.Library.Summary(), "library: ")) + "\n")
|
||||
b.WriteString(pad + " " + sFaint.Render(padRight(tr("library"), 18)) + sText.Render(strings.TrimPrefix(snap.Library.Summary(), "library: ")) + "\n")
|
||||
}
|
||||
return strings.TrimRight(b.String(), "\n")
|
||||
}
|
||||
@@ -1016,7 +1020,7 @@ func (m model) viewName() string {
|
||||
func hints(kv ...string) string {
|
||||
var parts []string
|
||||
for i := 0; i+1 < len(kv); i += 2 {
|
||||
parts = append(parts, sKey.Render(kv[i])+" "+sMuted.Render(kv[i+1]))
|
||||
parts = append(parts, sKey.Render(kv[i])+" "+sMuted.Render(tr(kv[i+1])))
|
||||
}
|
||||
return strings.Join(parts, sFaint.Render(" · "))
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package gui
|
||||
package uilang
|
||||
|
||||
import (
|
||||
"os"
|
||||
@@ -6,13 +6,13 @@ import (
|
||||
"github.com/yetone/magpie/internal/proc"
|
||||
)
|
||||
|
||||
// systemLang is the first of the Mac's preferred languages, the one the
|
||||
// System is the first of the Mac's preferred languages, the one the
|
||||
// page's navigator.language is; an app opened from Finder has no LANG.
|
||||
func systemLang() string {
|
||||
func System() string {
|
||||
if out, err := proc.Command("defaults", "read", "-g", "AppleLanguages").Output(); err == nil {
|
||||
if l := firstAppleLang(string(out)); l != "" {
|
||||
return l
|
||||
}
|
||||
}
|
||||
return envLang(os.Getenv)
|
||||
return Env(os.Getenv)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//go:build !darwin && !windows
|
||||
|
||||
package uilang
|
||||
|
||||
import "os"
|
||||
|
||||
// System is the system's language, as the environment names it.
|
||||
func System() string { return Env(os.Getenv) }
|
||||
@@ -1,10 +1,10 @@
|
||||
package gui
|
||||
package uilang
|
||||
|
||||
import "golang.org/x/sys/windows"
|
||||
|
||||
// systemLang is the user's first display language, the one WebView2 hands
|
||||
// System is the user's first display language, the one WebView2 hands
|
||||
// the page as navigator.language.
|
||||
func systemLang() string {
|
||||
func System() string {
|
||||
if l, err := windows.GetUserPreferredUILanguages(windows.MUI_LANGUAGE_NAME); err == nil && len(l) > 0 {
|
||||
return l[0]
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
// Package uilang is the language magpie speaks in: the one the user picked
|
||||
// in Settings (settings.Lang), or with "system" the system's. The GUI's
|
||||
// page picks its own the same way (i18n.js setLocale and sysLocale); the
|
||||
// tray, notices and the TUI ask Pick.
|
||||
package uilang
|
||||
|
||||
import "strings"
|
||||
|
||||
// Pick is the language for the setting pref: pref itself when it names
|
||||
// one, else, with "system" (or none), the system's: Traditional Chinese
|
||||
// for Taiwan, Hong Kong, Macau and any zh-Hant (zh_TW.UTF-8, zh-Hant-TW),
|
||||
// Simplified for any other zh, Japanese for any ja, German for any de,
|
||||
// English for the rest.
|
||||
func Pick(pref string, system func() string) string {
|
||||
switch pref {
|
||||
case "en", "zh", "zh-TW", "ja", "de":
|
||||
return pref
|
||||
}
|
||||
switch sys := strings.ReplaceAll(strings.ToLower(system()), "_", "-"); {
|
||||
case zhTraditional(sys):
|
||||
return "zh-TW"
|
||||
case strings.HasPrefix(sys, "zh"):
|
||||
return "zh"
|
||||
case strings.HasPrefix(sys, "ja"):
|
||||
return "ja"
|
||||
case strings.HasPrefix(sys, "de"):
|
||||
return "de"
|
||||
}
|
||||
return "en"
|
||||
}
|
||||
|
||||
// zhTraditional says a lowercased, dashed system tag is Traditional
|
||||
// Chinese, as the page's sysLocale does.
|
||||
func zhTraditional(sys string) bool {
|
||||
for _, p := range []string{"zh-tw", "zh-hk", "zh-mo", "zh-hant"} {
|
||||
if sys == p || strings.HasPrefix(sys, p+"-") || strings.HasPrefix(sys, p+".") || strings.HasPrefix(sys, p+"@") {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Env is the language the environment names: the first of LC_ALL,
|
||||
// LC_MESSAGES, LANG and LANGUAGE set to one.
|
||||
func Env(getenv func(string) string) string {
|
||||
for _, k := range []string{"LC_ALL", "LC_MESSAGES", "LANG", "LANGUAGE"} {
|
||||
if v := getenv(k); v != "" && v != "C" && v != "POSIX" && !strings.HasPrefix(v, "C.") {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// firstAppleLang is the first entry `defaults read -g AppleLanguages`
|
||||
// prints: ( "zh-Hans-CN", "en-US" ), one to a line, quoted or not.
|
||||
func firstAppleLang(out string) string {
|
||||
for _, line := range strings.Split(out, "\n") {
|
||||
s := strings.Trim(strings.TrimSpace(line), `",`)
|
||||
if s != "" && s != "(" && s != ")" {
|
||||
return s
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package uilang
|
||||
|
||||
import "testing"
|
||||
|
||||
// Pick follows the setting, and with "system" (or none) the system's
|
||||
// language, as the GUI page's sysLocale does (#301).
|
||||
func TestPick(t *testing.T) {
|
||||
en := func() string { return "en-US" }
|
||||
for _, c := range []struct {
|
||||
pref, sys, want string
|
||||
}{
|
||||
{"zh", "en-US", "zh"},
|
||||
{"en", "zh-Hans-CN", "en"},
|
||||
{"system", "zh-Hans-CN", "zh"},
|
||||
{"", "zh_CN.UTF-8", "zh"},
|
||||
{"system", "", "en"},
|
||||
{"system", "ja-JP", "ja"},
|
||||
{"", "de_AT.UTF-8", "de"},
|
||||
{"system", "zh-Hant-TW", "zh-TW"},
|
||||
{"", "zh_HK", "zh-TW"},
|
||||
{"system", "zh-Hans-HK", "zh"},
|
||||
{"bogus", "fr-FR", "en"},
|
||||
} {
|
||||
if got := Pick(c.pref, func() string { return c.sys }); got != c.want {
|
||||
t.Errorf("Pick(%q, %q) = %s, want %s", c.pref, c.sys, got, c.want)
|
||||
}
|
||||
}
|
||||
if got := Pick("de", en); got != "de" {
|
||||
t.Errorf("Pick(de) = %s", got)
|
||||
}
|
||||
env := map[string]string{"LC_ALL": "C", "LANG": "zh_CN.UTF-8"}
|
||||
if got := Env(func(k string) string { return env[k] }); got != "zh_CN.UTF-8" {
|
||||
t.Errorf("Env skips C: %q", got)
|
||||
}
|
||||
if got := firstAppleLang("(\n \"zh-Hans-CN\",\n \"en-US\"\n)\n"); got != "zh-Hans-CN" {
|
||||
t.Errorf("firstAppleLang: %q", got)
|
||||
}
|
||||
if got := firstAppleLang("(\n en,\n \"zh-Hans\"\n)\n"); got != "en" {
|
||||
t.Errorf("firstAppleLang unquoted: %q", got)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user