From f8ceed9ec093779cfb1a22a46fee704dfde89f5a Mon Sep 17 00:00:00 2001 From: qiyinxi Date: Wed, 18 Nov 2026 18:46:14 +0100 Subject: [PATCH 1/3] =?UTF-8?q?feat:=20=E7=AE=A1=E7=90=86=E5=99=A8?= =?UTF-8?q?=E5=92=8C=E5=91=BD=E4=BB=A4=E8=A1=8C=E7=9A=84=E8=8B=B1=E6=96=87?= =?UTF-8?q?=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 代码里照旧写中文,中文原文就是键:internal/i18n 按包放英文表,格式串和拼接按模式反向匹配。 只在给人看的地方翻:管理器的回答和事件、页面自己的字符串、托盘和消息框、命令行输出到控制台的人读输出。 --json、MCP、日志、问题包、mas-avd.json 不变。语言按 MODAVD_LANG、设置里选的、系统界面语言依次决定, 设置页可以切换。TestCatalog 查漏翻、过期、参数对不上和页面里写在 t() 外面的中文。 Refs ModAVD/ModAVD#165 --- changelog.d/165-english.feat.md | 1 + cmd/modavd-gui/main.go | 2 + internal/cli/cli.go | 20 + internal/cli/format.go | 8 + internal/cli/output.go | 4 +- internal/i18n/README.md | 63 ++ internal/i18n/catalog_test.go | 621 +++++++++++++++ internal/i18n/i18n.go | 267 +++++++ internal/i18n/json.go | 134 ++++ internal/i18n/locales/en/adb.json | 55 ++ internal/i18n/locales/en/apk.json | 20 + internal/i18n/locales/en/appproxy.json | 74 ++ internal/i18n/locales/en/avd.json | 29 + internal/i18n/locales/en/bosskey.json | 16 + internal/i18n/locales/en/cli.json | 460 +++++++++++ internal/i18n/locales/en/components.json | 226 ++++++ internal/i18n/locales/en/diagnostics.json | 4 + internal/i18n/locales/en/download.json | 28 + internal/i18n/locales/en/emu.json | 831 ++++++++++++++++++++ internal/i18n/locales/en/extra.json | 9 + internal/i18n/locales/en/guest.json | 8 + internal/i18n/locales/en/guestpatch.json | 6 + internal/i18n/locales/en/host.json | 4 + internal/i18n/locales/en/hostproxy.json | 5 + internal/i18n/locales/en/jsonord.json | 16 + internal/i18n/locales/en/logx.json | 6 + internal/i18n/locales/en/macos.json | 94 +++ internal/i18n/locales/en/mcp.json | 47 ++ internal/i18n/locales/en/modavd-gui.json | 38 + internal/i18n/locales/en/modavd-proxyd.json | 3 + internal/i18n/locales/en/ndkfix.json | 9 + internal/i18n/locales/en/playstore.json | 84 ++ internal/i18n/locales/en/regional.json | 14 + internal/i18n/locales/en/report.json | 349 ++++++++ internal/i18n/locales/en/root.json | 54 ++ internal/i18n/locales/en/ui.json | 263 +++++++ internal/i18n/locales/en/update.json | 299 +++++++ internal/i18n/locales/en/vkfix.json | 11 + internal/i18n/locales/en/web.json | 648 +++++++++++++++ internal/i18n/locales/en/win.json | 60 ++ internal/i18n/match.go | 301 +++++++ internal/i18n/match_test.go | 123 +++ internal/i18n/pref.go | 137 ++++ internal/i18n/system_other.go | 39 + internal/i18n/system_windows.go | 36 + internal/ui/API.en.md | 2 + internal/ui/API.md | 2 + internal/ui/events.go | 2 +- internal/ui/http.go | 5 +- internal/ui/locale.go | 74 ++ internal/ui/locale_test.go | 52 ++ internal/ui/web/app.css | 4 +- internal/ui/web/dev/mock.js | 5 + internal/ui/web/index.html | 20 +- internal/ui/web/js/actions.js | 66 +- internal/ui/web/js/api.js | 10 +- internal/ui/web/js/app.js | 54 +- internal/ui/web/js/cards.js | 116 +-- internal/ui/web/js/diagnostics.js | 137 ++-- internal/ui/web/js/format.js | 120 +-- internal/ui/web/js/forms.js | 183 ++--- internal/ui/web/js/gles32.js | 19 +- internal/ui/web/js/i18n.js | 114 +++ internal/ui/web/js/panels.js | 107 +-- internal/ui/web/js/playstore.js | 39 +- internal/ui/web/js/proxy.js | 109 +-- internal/ui/web/js/regional.js | 21 +- internal/ui/web/js/ui.js | 11 +- internal/ui/web/js/update.js | 115 +-- internal/ui/web/js/viewer.js | 75 +- internal/win/api_windows.go | 6 +- internal/win/notice.go | 6 +- internal/win/tray.go | 6 +- 73 files changed, 6419 insertions(+), 587 deletions(-) create mode 100644 changelog.d/165-english.feat.md create mode 100644 internal/i18n/README.md create mode 100644 internal/i18n/catalog_test.go create mode 100644 internal/i18n/i18n.go create mode 100644 internal/i18n/json.go create mode 100644 internal/i18n/locales/en/adb.json create mode 100644 internal/i18n/locales/en/apk.json create mode 100644 internal/i18n/locales/en/appproxy.json create mode 100644 internal/i18n/locales/en/avd.json create mode 100644 internal/i18n/locales/en/bosskey.json create mode 100644 internal/i18n/locales/en/cli.json create mode 100644 internal/i18n/locales/en/components.json create mode 100644 internal/i18n/locales/en/diagnostics.json create mode 100644 internal/i18n/locales/en/download.json create mode 100644 internal/i18n/locales/en/emu.json create mode 100644 internal/i18n/locales/en/extra.json create mode 100644 internal/i18n/locales/en/guest.json create mode 100644 internal/i18n/locales/en/guestpatch.json create mode 100644 internal/i18n/locales/en/host.json create mode 100644 internal/i18n/locales/en/hostproxy.json create mode 100644 internal/i18n/locales/en/jsonord.json create mode 100644 internal/i18n/locales/en/logx.json create mode 100644 internal/i18n/locales/en/macos.json create mode 100644 internal/i18n/locales/en/mcp.json create mode 100644 internal/i18n/locales/en/modavd-gui.json create mode 100644 internal/i18n/locales/en/modavd-proxyd.json create mode 100644 internal/i18n/locales/en/ndkfix.json create mode 100644 internal/i18n/locales/en/playstore.json create mode 100644 internal/i18n/locales/en/regional.json create mode 100644 internal/i18n/locales/en/report.json create mode 100644 internal/i18n/locales/en/root.json create mode 100644 internal/i18n/locales/en/ui.json create mode 100644 internal/i18n/locales/en/update.json create mode 100644 internal/i18n/locales/en/vkfix.json create mode 100644 internal/i18n/locales/en/web.json create mode 100644 internal/i18n/locales/en/win.json create mode 100644 internal/i18n/match.go create mode 100644 internal/i18n/match_test.go create mode 100644 internal/i18n/pref.go create mode 100644 internal/i18n/system_other.go create mode 100644 internal/i18n/system_windows.go create mode 100644 internal/ui/locale.go create mode 100644 internal/ui/locale_test.go create mode 100644 internal/ui/web/js/i18n.js diff --git a/changelog.d/165-english.feat.md b/changelog.d/165-english.feat.md new file mode 100644 index 00000000..241d10e3 --- /dev/null +++ b/changelog.d/165-english.feat.md @@ -0,0 +1 @@ +管理器和命令行有了英文界面:按系统语言自动选,设置里可以改 (ModAVD/ModAVD#165) diff --git a/cmd/modavd-gui/main.go b/cmd/modavd-gui/main.go index ed591b60..fbadc332 100644 --- a/cmd/modavd-gui/main.go +++ b/cmd/modavd-gui/main.go @@ -39,6 +39,7 @@ import ( "modavd/internal/emu" "modavd/internal/errs" "modavd/internal/host" + "modavd/internal/i18n" "modavd/internal/logx" "modavd/internal/root" "modavd/internal/ui" @@ -112,6 +113,7 @@ func printVersion() int { } func run(args []string) (code int) { + i18n.Init() var log *logx.Logger defer func() { // A GUI process has no console: a panic would otherwise end it without a trace. diff --git a/internal/cli/cli.go b/internal/cli/cli.go index 63dafd40..08cfd8de 100644 --- a/internal/cli/cli.go +++ b/internal/cli/cli.go @@ -115,6 +115,7 @@ import ( "modavd/internal/emu" "modavd/internal/errs" "modavd/internal/host" + "modavd/internal/i18n" "modavd/internal/logx" "modavd/internal/mcp" "modavd/internal/root" @@ -217,6 +218,11 @@ func readerIsTerminal(r io.Reader) bool { return ok && f != nil && fileIsTerminal(f) } +func writerIsTerminal(w io.Writer) bool { + f, ok := w.(*os.File) + return ok && f != nil && fileIsTerminal(f) +} + // Main runs one command and returns the process exit code (errs.ExitCode, see the package comment). func Main(args []string, stdin io.Reader, stdout, stderr io.Writer) int { if len(args) > 0 { @@ -237,6 +243,7 @@ func Main(args []string, stdin io.Reader, stdout, stderr io.Writer) int { return emu.RunDiagnosticArchive(args[1:], stderr) } } + i18n.Init() // StartOrphan re-runs this executable as the spawn helper. if exe, err := os.Executable(); err == nil { host.SetOrphanHelper(exe) @@ -298,6 +305,19 @@ func run(ctx context.Context, args []string, stdin io.Reader, stdout, stderr io. d.stdinTerminal = readerIsTerminal } inv, perr := parseArgs(args) + // Human output in the language of the user (ModAVD/ModAVD#165), on a console only: what goes to a file or a pipe + // (the manager's update log, scripts) stays as before unless MODAVD_LANG asks for a language. --json, adb and + // mcp stay byte for byte, and so does what shell prints (the guest's own output). + if lang := i18n.Current(); !inv.json { + raw := inv.cmd != nil && inv.cmd.raw + forced := os.Getenv(i18n.EnvVar) != "" + if !raw && (inv.cmd == nil || inv.cmd.name != "shell") && (forced || writerIsTerminal(stdout)) { + stdout = i18n.Writer(stdout, lang) + } + if !raw && (forced || writerIsTerminal(stderr)) { + stderr = i18n.Writer(stderr, lang) + } + } log := newLogger(stderr, inv.globals) out := &output{stdout: stdout, stderr: stderr, json: inv.json, raw: inv.cmd != nil && inv.cmd.raw, log: log} if perr != nil { diff --git a/internal/cli/format.go b/internal/cli/format.go index c69089dd..45401ec7 100644 --- a/internal/cli/format.go +++ b/internal/cli/format.go @@ -12,6 +12,7 @@ import ( "modavd/internal/avd" "modavd/internal/components" "modavd/internal/emu" + "modavd/internal/i18n" ) // Human-readable summaries (stdout without --json). Wording follows AUTO-MAS where it has a message for the same @@ -134,6 +135,13 @@ func displayWidth(s string) int { // writeTable aligns columns by display width (text/tabwriter counts runes, which misaligns Chinese). func writeTable(w io.Writer, rows [][]string) { + if lang := i18n.LangOf(w); lang != i18n.Chinese { + for _, row := range rows { + for k, cell := range row { + row[k] = i18n.Translate(lang, cell) + } + } + } var widths []int for _, row := range rows { for k, cell := range row { diff --git a/internal/cli/output.go b/internal/cli/output.go index 8b80e8a6..bfb32956 100644 --- a/internal/cli/output.go +++ b/internal/cli/output.go @@ -7,6 +7,7 @@ import ( "io" "modavd/internal/errs" + "modavd/internal/i18n" "modavd/internal/logx" ) @@ -54,7 +55,8 @@ func (o *output) success(cmd *command, data any) int { return 0 } if cmd.human != nil { - cmd.human(o.stdout, data) + // Text fields are translated before the summary is laid out (columns, "标题:原因" lines). + cmd.human(o.stdout, i18n.Localize(i18n.LangOf(o.stdout), data)) } return 0 } diff --git a/internal/i18n/README.md b/internal/i18n/README.md new file mode 100644 index 00000000..370c65a6 --- /dev/null +++ b/internal/i18n/README.md @@ -0,0 +1,63 @@ +# Translations / 界面翻译 + +The code is written in Chinese, and the Chinese text is the key: `locales//.json` maps each Chinese +string the code shows to its translation (`web.json` holds the page's own strings). See the package comment in +`i18n.go` for where translation happens and what stays Chinese. + +代码里照旧写中文,中文原文就是键。新加或改了中文字符串以后: + +``` +go test ./internal/i18n -run TestCatalog -update # 把缺的键以 "" 加进表 +go test ./internal/i18n -run TestCatalog -update -prune # 同时删掉源码里已经没有的键 +``` + +再把 `""` 填成英文。`null` 表示故意不翻(只进日志文件、问题包,或者是拿来匹配中文输出的文字、发进客体的命令)。 +`TestCatalog` 查四件事:表里有没有漏的、有没有过期的、译文的参数(`%d`、`%[2]s`、页面的 `{name}`)和原文对不对得上、 +页面里有没有写在 `t()` 外面的中文。 + +`extra.json` 放代码拼出来、但拼的那段本身没有中文词的句式(比如 `fmt.Sprintf("%s%s(%s)", 标题, "通过", 原因)`,按拼好的样子写成 `%s通过(%s)`),不查是否过期。 + +## Writing the English + +- Keep every verb of the key (`%d`, `%s`, `%v`, `%q`, `%.1f` …). To reorder, index them: `%[2]s … %[1]d`. A key + built from a concatenation has `%v` for each non-literal part. +- Plain, short English; sentence case; no Chinese punctuation. Keep leading / trailing spaces and newlines as in the + key. +- A message is often built from several keys ("外层:内层"): translate each key on its own so it reads well alone. +- `null` only for text no person sees in the manager or the CLI: problem report contents, patterns matched against + Chinese output of Windows or games, commands and values sent to the guest, file names. + +## Terms + +| 中文 | English | +| --- | --- | +| 实例 / 实例 3 | instance / instance 3 | +| 新建 | create | +| 开机 / 启动 | start (the instance); boot (Android booting) | +| 关机 / 强制关机 | shut down / force stop | +| 根目录 | root folder | +| 管理器 | manager | +| 命令行 | command line, CLI | +| 组件 / 补全组件 | components / Fetch components | +| 数据盘 / 自动扩盘 | data disk / automatic size | +| 无头 | headless | +| 老板键 | boss key | +| 托盘 | tray | +| 执行桥 | execution bridge | +| 问题包 | problem report | +| 电脑检查 | System check | +| 更新源 | update source | +| Mirror 酱 | MirrorChyan | +| 客体 / 宿主 | guest / host | +| 首次初始化 | initial setup | +| 更多操作 | More actions | +| 设置 | Settings | +| 检查更新 / 更新 | Check for updates / Update | +| 打开管理器 / 退出 | Open manager / Exit | +| 帧率 | frame rate (FPS) | +| 分辨率 | resolution | +| 加速 | acceleration | +| 诊断 | diagnostics | +| 代理 | proxy | +| 安卓 | Android | +| 星铁 / 终末地 / 1999 / 明日方舟 / 阴阳师 | Honkai: Star Rail / Arknights: Endfield / Reverse: 1999 / Arknights / Onmyoji | diff --git a/internal/i18n/catalog_test.go b/internal/i18n/catalog_test.go new file mode 100644 index 00000000..030e00ff --- /dev/null +++ b/internal/i18n/catalog_test.go @@ -0,0 +1,621 @@ +package i18n + +import ( + "bytes" + "encoding/json" + "flag" + "fmt" + "go/ast" + "go/parser" + "go/token" + "os" + "path/filepath" + "regexp" + "sort" + "strconv" + "strings" + "testing" +) + +// go test ./internal/i18n -run TestCatalog -update adds the Chinese strings of the source that the tables lack, as "" +// (to translate) in locales//.json; -prune also drops keys the source no longer has. +var ( + update = flag.Bool("update", false, "add missing keys to the tables") + prune = flag.Bool("prune", false, "with -update: drop keys the source no longer has") +) + +// repoRoot is the module root (two levels up from this package). +func repoRoot(t *testing.T) string { + t.Helper() + dir, err := filepath.Abs(filepath.Join("..", "..")) + if err != nil { + t.Fatal(err) + } + return dir +} + +// sourceKey is one string the code shows, and the table (file name without .json) it belongs to. +type sourceKey struct { + key, group, pos string +} + +// goKeys extracts the Chinese strings of every non-test Go file: string literals, a concatenation chain as one key +// with %v for each operand that is not a literal. +func goKeys(t *testing.T, root string) []sourceKey { + t.Helper() + var out []sourceKey + err := filepath.WalkDir(root, func(p string, d os.DirEntry, err error) error { + if err != nil { + return err + } + if d.IsDir() { + name := d.Name() + if p != root && (strings.HasPrefix(name, ".") || name == "testdata" || name == "web" || name == "i18n") { + return filepath.SkipDir + } + return nil + } + if !strings.HasSuffix(p, ".go") || strings.HasSuffix(p, "_test.go") { + return nil + } + rel, _ := filepath.Rel(root, p) + group := groupOf(filepath.ToSlash(rel)) + fs := token.NewFileSet() + f, err := parser.ParseFile(fs, p, nil, parser.SkipObjectResolution) + if err != nil { + return err + } + inChain := map[ast.Node]bool{} + var tags = map[*ast.BasicLit]bool{} + ast.Inspect(f, func(n ast.Node) bool { + switch n := n.(type) { + case *ast.Field: + if n.Tag != nil { + tags[n.Tag] = true + } + case *ast.BinaryExpr: + if n.Op != token.ADD || inChain[n] { + return true + } + ops := flattenAdd(n, inChain) + if !anyStringLit(ops) { + return true + } + var b strings.Builder + for _, op := range ops { + if bl, ok := op.(*ast.BasicLit); ok && bl.Kind == token.STRING { + v, _ := strconv.Unquote(bl.Value) + b.WriteString(v) + inChain[bl] = true + } else { + b.WriteString("%v") + } + } + if k := b.String(); HasHan(k) { + out = append(out, sourceKey{k, group, fs.Position(n.Pos()).String()}) + } + case *ast.BasicLit: + if n.Kind != token.STRING || inChain[n] || tags[n] { + return true + } + v, err := strconv.Unquote(n.Value) + if err == nil && HasHan(v) { + out = append(out, sourceKey{v, group, fs.Position(n.Pos()).String()}) + } + } + return true + }) + return nil + }) + if err != nil { + t.Fatal(err) + } + return out +} + +// flattenAdd lists the operands of a chain of + (parentheses included), marking the inner nodes. +func flattenAdd(e ast.Expr, seen map[ast.Node]bool) []ast.Expr { + switch x := e.(type) { + case *ast.ParenExpr: + if b, ok := x.X.(*ast.BinaryExpr); ok && b.Op == token.ADD { + return flattenAdd(b, seen) + } + case *ast.BinaryExpr: + if x.Op == token.ADD { + seen[x] = true + return append(flattenAdd(x.X, seen), flattenAdd(x.Y, seen)...) + } + } + return []ast.Expr{e} +} + +func anyStringLit(ops []ast.Expr) bool { + for _, op := range ops { + if bl, ok := op.(*ast.BasicLit); ok && bl.Kind == token.STRING { + return true + } + } + return false +} + +// groupOf: internal//… is , cmd//… is , the root package is cli. +func groupOf(rel string) string { + parts := strings.Split(rel, "/") + if len(parts) >= 3 && (parts[0] == "internal" || parts[0] == "cmd") { + return parts[1] + } + return "cli" +} + +// webDir holds the page. +func webDir(root string) string { return filepath.Join(root, "internal", "ui", "web") } + +// webKeys are the strings the page passes to t() and the data-t texts of index.html; untranslated lists the Chinese +// literals outside t() (each a bug: the page would show it in every language). +func webKeys(t *testing.T, root string) (keys []sourceKey, untranslated []string) { + t.Helper() + files, _ := filepath.Glob(filepath.Join(webDir(root), "js", "*.js")) + for _, f := range files { + b, err := os.ReadFile(f) + if err != nil { + t.Fatal(err) + } + name := filepath.Base(f) + lines := strings.Split(string(b), "\n") + for _, s := range scanJS(string(b)) { + if !HasHan(s.text) { + continue + } + // "// i18n: keep" on the line: Chinese on purpose (a language's own name, text matched as it is). + if s.line-1 < len(lines) && strings.Contains(lines[s.line-1], "i18n: keep") { + continue + } + pos := fmt.Sprintf("%s:%d", name, s.line) + if s.inT { + keys = append(keys, sourceKey{s.text, "web", pos}) + } else { + untranslated = append(untranslated, fmt.Sprintf("%s %q", pos, s.text)) + } + } + } + b, err := os.ReadFile(filepath.Join(webDir(root), "index.html")) + if err != nil { + t.Fatal(err) + } + for _, k := range htmlKeys(string(b)) { + keys = append(keys, sourceKey{k, "web", "index.html"}) + } + // CSS text (content: "…") cannot be translated: use content: attr(data-…) with the attribute set through t(). + css, err := os.ReadFile(filepath.Join(webDir(root), "app.css")) + if err != nil { + t.Fatal(err) + } + for _, m := range cssContentRE.FindAllString(commentCSSRE.ReplaceAllString(string(css), ""), -1) { + if HasHan(m) { + untranslated = append(untranslated, "app.css "+m) + } + } + if rest := htmlUntranslated(string(b)); len(rest) > 0 { + for _, r := range rest { + untranslated = append(untranslated, "index.html "+strconv.Quote(r)) + } + } + return keys, untranslated +} + +type jsString struct { + text string + line int + inT bool // the first argument of t( … ) +} + +// scanJS lists the string literals of a script (comments skipped; a template literal is one string, its ${…} parts +// scanned too). A literal is inT when it directly follows "t(" or ", t(" style calls: the identifier t, then "(". +func scanJS(src string) []jsString { + var out []jsString + line := 1 + lastIdent, lastTok := "", "" + prevIdent := "" // identifier before the last "(" + i := 0 + var scan func(end byte) // scans until end (0: end of input) + readQuoted := func(q byte) string { + var b strings.Builder + i++ // opening quote + for i < len(src) && src[i] != q { + if src[i] == '\\' && i+1 < len(src) { + switch src[i+1] { + case 'n': + b.WriteByte('\n') + case 't': + b.WriteByte('\t') + case '\n': + line++ + default: + b.WriteByte(src[i+1]) + } + i += 2 + continue + } + if src[i] == '\n' { + line++ + } + b.WriteByte(src[i]) + i++ + } + i++ // closing quote + return b.String() + } + readTemplate := func() string { + var b strings.Builder + i++ + for i < len(src) && src[i] != '`' { + if src[i] == '\\' && i+1 < len(src) { + b.WriteByte(src[i+1]) + i += 2 + continue + } + if src[i] == '$' && i+1 < len(src) && src[i+1] == '{' { + b.WriteString("${…}") + i += 2 + scan('}') + i++ + continue + } + if src[i] == '\n' { + line++ + } + b.WriteByte(src[i]) + i++ + } + i++ + return b.String() + } + regexAllowed := func() bool { + return lastTok == "" || strings.Contains("(,=:[!&|?{};+-*%<>~^", lastTok) || lastIdent == "return" && lastTok == "ident" + } + scan = func(end byte) { + depth := 0 + for i < len(src) { + c := src[i] + switch { + case end != 0 && c == end && depth == 0: + return + case c == '{': + depth++ + lastTok = "{" + i++ + case c == '}': + depth-- + lastTok = "}" + i++ + case c == '\n': + line++ + i++ + case c == ' ' || c == '\t' || c == '\r': + i++ + case strings.HasPrefix(src[i:], "//"): + for i < len(src) && src[i] != '\n' { + i++ + } + case strings.HasPrefix(src[i:], "/*"): + j := strings.Index(src[i+2:], "*/") + if j < 0 { + i = len(src) + break + } + line += strings.Count(src[i:i+2+j], "\n") + i += j + 4 + case c == '\'' || c == '"': + l := line + s := readQuoted(c) + out = append(out, jsString{s, l, lastTok == "(" && prevIdent == "t"}) + lastTok, lastIdent = "str", "" + case c == '`': + l := line + s := readTemplate() + out = append(out, jsString{s, l, false}) + lastTok, lastIdent = "str", "" + case c == '/' && regexAllowed(): + i++ + inClass := false + for i < len(src) && (src[i] != '/' || inClass) && src[i] != '\n' { + if src[i] == '\\' { + i++ + } else if src[i] == '[' { + inClass = true + } else if src[i] == ']' { + inClass = false + } + i++ + } + i++ + for i < len(src) && isIdentByte(src[i]) { + i++ + } + lastTok, lastIdent = "regex", "" + case isIdentByte(c): + j := i + for j < len(src) && isIdentByte(src[j]) { + j++ + } + lastIdent = src[i:j] + lastTok = "ident" + i = j + default: + if c == '(' { + if lastTok == "ident" { + prevIdent = lastIdent + } else { + prevIdent = "" + } + } + lastTok = string(c) + lastIdent = "" + i++ + } + } + } + scan(0) + return out +} + +func isIdentByte(c byte) bool { + return c == '_' || c == '$' || c >= '0' && c <= '9' || c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c >= 0x80 +} + +var ( + dataTRE = regexp.MustCompile(`(?s)<([a-z0-9]+)[^>]*\sdata-t(?:\s|>|=)[^>]*>(.*?)`) + attrRE = regexp.MustCompile(`\s(title|placeholder|aria-label|alt)="([^"]*)"`) + tagRE = regexp.MustCompile(`(?s)<[^>]*>`) + commentRE = regexp.MustCompile(`(?s)`) + cssContentRE = regexp.MustCompile(`content:\s*("[^"]*"|'[^']*')`) + commentCSSRE = regexp.MustCompile(`(?s)/\*.*?\*/`) + scriptRE = regexp.MustCompile(`(?s)`) +) + +// htmlKeys: the text of each element marked data-t (no child elements), and every Chinese title / placeholder / +// aria-label / alt attribute (the page translates those wherever they are). +func htmlKeys(src string) []string { + src = commentRE.ReplaceAllString(src, "") + var out []string + for _, m := range dataTRE.FindAllStringSubmatch(src, -1) { + if s := strings.TrimSpace(m[2]); HasHan(s) { + out = append(out, s) + } + } + for _, m := range attrRE.FindAllStringSubmatch(src, -1) { + if HasHan(m[2]) { + out = append(out, m[2]) + } + } + return out +} + +// htmlUntranslated is Chinese text of index.html outside data-t elements and the attributes above. +func htmlUntranslated(src string) []string { + src = commentRE.ReplaceAllString(src, "") + src = scriptRE.ReplaceAllString(src, "") + src = dataTRE.ReplaceAllString(src, "") + src = attrRE.ReplaceAllString(src, "") + var out []string + for _, piece := range tagRE.Split(src, -1) { + if s := strings.TrimSpace(piece); HasHan(s) { + out = append(out, s) + } + } + // Chinese left inside a tag: an attribute the page does not translate. + for _, tag := range tagRE.FindAllString(src, -1) { + if HasHan(tag) { + out = append(out, tag) + } + } + return out +} + +// table is one locales//.json: nil values are kept untranslated on purpose. +type table map[string]*string + +func readTable(t *testing.T, path string) table { + t.Helper() + b, err := os.ReadFile(path) + if os.IsNotExist(err) { + return table{} + } + if err != nil { + t.Fatal(err) + } + var tb table + if err := json.Unmarshal(b, &tb); err != nil { + t.Fatalf("%s: %v", path, err) + } + return tb +} + +func writeTable(t *testing.T, path string, tb table) { + t.Helper() + keys := make([]string, 0, len(tb)) + for k := range tb { + keys = append(keys, k) + } + sort.Strings(keys) + var b bytes.Buffer + b.WriteString("{\n") + for n, k := range keys { + kb, _ := marshalNoEscape(k) + b.WriteString(" ") + b.Write(kb) + b.WriteString(": ") + if tb[k] == nil { + b.WriteString("null") + } else { + vb, _ := marshalNoEscape(*tb[k]) + b.Write(vb) + } + if n < len(keys)-1 { + b.WriteByte(',') + } + b.WriteByte('\n') + } + b.WriteString("}\n") + if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(path, b.Bytes(), 0o644); err != nil { + t.Fatal(err) + } +} + +func marshalNoEscape(s string) ([]byte, error) { + var b bytes.Buffer + enc := json.NewEncoder(&b) + enc.SetEscapeHTML(false) + if err := enc.Encode(s); err != nil { + return nil, err + } + return bytes.TrimRight(b.Bytes(), "\n"), nil +} + +// TestCatalog checks every table against the source: each string the code or the page shows has an entry (null or +// a translation, not ""), no entry is stale, and a translation uses the same arguments as its key. +func TestCatalog(t *testing.T) { + root := repoRoot(t) + src := goKeys(t, root) + web, untranslated := webKeys(t, root) + src = append(src, web...) + for _, u := range untranslated { + t.Errorf("page text outside t(): %s", u) + } + want := map[string]map[string]string{} // group → key → first position + for _, k := range src { + if want[k.group] == nil { + want[k.group] = map[string]string{} + } + if _, ok := want[k.group][k.key]; !ok { + want[k.group][k.key] = k.pos + } + } + for _, lang := range tableCodes() { + dir := filepath.Join("locales", lang) + groups := map[string]bool{} + for g := range want { + groups[g] = true + } + existing, _ := filepath.Glob(filepath.Join(dir, "*.json")) + for _, f := range existing { + groups[strings.TrimSuffix(filepath.Base(f), ".json")] = true + } + var missing []string + for g := range groups { + path := filepath.Join(dir, g+".json") + tb := readTable(t, path) + changed := false + for k, pos := range want[g] { + v, ok := tb[k] + if !ok { + if *update { + empty := "" + tb[k] = &empty + changed = true + } + missing = append(missing, fmt.Sprintf("%s: %s %q", lang, pos, k)) + continue + } + if v != nil && *v == "" { + missing = append(missing, fmt.Sprintf("%s: %s %q (empty)", lang, pos, k)) + } + } + for k, v := range tb { + // extra.json: messages the code composes from parts without a key of their own (see README). + if _, ok := want[g][k]; !ok && g != "extra" { + if *update && *prune { + delete(tb, k) + changed = true + continue + } + t.Errorf("%s/%s.json: stale key %q", lang, g, k) + continue + } + if v != nil && *v != "" { + if err := sameArgs(g, k, *v); err != nil { + t.Errorf("%s/%s.json %q: %v", lang, g, k, err) + } + } + } + if changed { + writeTable(t, path, tb) + } + } + // One key, one translation: the tables are merged into one. + seen := map[string]string{} + for g := range groups { + if g == "web" { + continue // the page's own table, looked up on its own + } + for k, v := range readTable(t, filepath.Join(dir, g+".json")) { + if v == nil || *v == "" { + continue + } + k, val := strings.TrimSpace(k), strings.TrimSpace(*v) + if prev, ok := seen[k]; ok && prev != val { + t.Errorf("%s: %q has two translations: %q and %q (%s.json)", lang, k, prev, val, g) + } + seen[k] = val + } + } + sort.Strings(missing) + if n := len(missing); n > 0 { + show := missing + if len(show) > 40 { + show = show[:40] + } + t.Errorf("%d strings not translated (go test ./internal/i18n -run TestCatalog -update adds them):\n%s", n, strings.Join(show, "\n")) + } + } +} + +var braceRE = regexp.MustCompile(`\{(\w+)\}`) + +// sameArgs: a Go key and its translation take the same arguments (an explicit index may reorder them); a page key +// and its translation the same {names}. +func sameArgs(group, key, val string) error { + if group == "web" { + a, b := braceSet(key), braceSet(val) + if a != b { + return fmt.Errorf("placeholders %s, translation has %s", a, b) + } + return nil + } + a, b := argSet(parseFormat(key)), argSet(parseFormat(val)) + if a != b { + return fmt.Errorf("arguments %s, translation has %s", a, b) + } + return nil +} + +func braceSet(s string) string { + set := map[string]bool{} + for _, m := range braceRE.FindAllStringSubmatch(s, -1) { + set[m[1]] = true + } + keys := make([]string, 0, len(set)) + for k := range set { + keys = append(keys, k) + } + sort.Strings(keys) + return "{" + strings.Join(keys, ",") + "}" +} + +func argSet(segs []segment) string { + set := map[int]bool{} + for _, s := range segs { + if s.verb != "" { + set[s.arg] = true + } + } + keys := make([]int, 0, len(set)) + for k := range set { + keys = append(keys, k) + } + sort.Ints(keys) + return fmt.Sprint(keys) +} diff --git a/internal/i18n/i18n.go b/internal/i18n/i18n.go new file mode 100644 index 00000000..ae9384dd --- /dev/null +++ b/internal/i18n/i18n.go @@ -0,0 +1,267 @@ +// Package i18n translates what ModAVD shows to people (ModAVD/ModAVD#165). +// +// The source text stays Chinese everywhere in the code, and it is also the key: locales//*.json map a Chinese +// string to its translation. Go format strings are keys as written ("实例 %d 正在关机"), and a message built from +// them is matched back against those patterns, the arguments translated in turn; the extractor (catalog_test.go, +// -update) also turns a concatenation "实例 " + name + " 已存在" into the key "实例 %v 已存在". The page's own +// strings use {name} placeholders and are looked up as written (web.json). +// +// Translation happens only where text is shown: the manager's HTTP answers and events, the CLI's human output, the +// GUI's dialogs and tray. What machines read (--json, MCP, exit codes, error codes, mas-avd.json) and what is written +// to logs and problem reports stays Chinese, byte for byte as before. +// +// A key whose value is null is shown untranslated on purpose (text that only goes into logs or reports); "" means +// not translated yet, which TestCatalogComplete reports. +package i18n + +import ( + "embed" + "encoding/json" + "io/fs" + "os" + "path" + "sort" + "strings" + "sync" + "sync/atomic" + "testing" + "unicode" + "unicode/utf8" +) + +// Languages. Chinese is the source language and needs no table. +const ( + Chinese = "zh-CN" + English = "en" +) + +// Language is one choice in the settings. +type Language struct { + Code string `json:"code"` + Name string `json:"name"` // in that language +} + +// Languages lists the languages the settings offer, the source language first. +func Languages() []Language { + out := []Language{{Chinese, "中文"}} + for _, code := range tableCodes() { + out = append(out, Language{code, nameOf(code)}) + } + return out +} + +func nameOf(code string) string { + if n, ok := names[code]; ok { + return n + } + return code +} + +var names = map[string]string{English: "English"} + +//go:embed locales +var localeFS embed.FS + +var current atomic.Value // string + +// Current is the language this process shows text in. Chinese until Init or Set: tests and library use see the source +// text. +func Current() string { + if v, ok := current.Load().(string); ok && v != "" { + return v + } + return Chinese +} + +// Set makes lang (a supported code) the language of this process; anything else falls back to the system's. +func Set(lang string) { + current.Store(Resolve(lang)) +} + +// Init picks the language from MODAVD_LANG, the saved preference, then the system. The CLI and the manager call it +// once at start. +func Init() { + pref := effectivePreference() + if testing.Testing() && os.Getenv(EnvVar) == "" { + // Tests of the CLI and the manager see the source text, whatever this computer's language and settings. + pref = Chinese + } + current.Store(Resolve(pref)) +} + +// Resolve maps a preference ("", "auto", a code, a locale such as "en-US" or "zh-TW") to a supported code. +func Resolve(pref string) string { + pref = strings.TrimSpace(pref) + if pref == "" || strings.EqualFold(pref, PrefAuto) { + return Match(SystemLocale()) + } + return Match(pref) +} + +// Match maps a locale name to a supported code: zh-* is Chinese, a language with a table is that language, anything +// else English. +func Match(locale string) string { + l := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(locale), "_", "-")) + if l == "zh" || strings.HasPrefix(l, "zh-") { + return Chinese + } + for _, code := range tableCodes() { + c := strings.ToLower(code) + if l == c || strings.HasPrefix(l, c+"-") { + return code + } + } + return English +} + +// Supported reports whether code is one of Languages. +func Supported(code string) bool { + for _, l := range Languages() { + if l.Code == code { + return true + } + } + return false +} + +// T translates s into the current language. +func T(s string) string { return Translate(Current(), s) } + +// Translate translates s into lang. Text without Chinese, and text the table does not know, come back unchanged. +func Translate(lang, s string) string { + if lang == Chinese || s == "" || !HasHan(s) { + return s + } + c := catalogFor(lang) + if c == nil { + return s + } + out := c.translate(s, 0) + out = capitalize(s, out) + if out != s && !HasHan(out) { + // Glue without Chinese words ("%s%s(%s)") is no key: its full-width punctuation is changed here. + out = fullWidth.Replace(out) + } + return out +} + +var fullWidth = strings.NewReplacer("(", " (", ")", ")", ":", ": ", ",", ", ", ";", "; ", "。", ". ", "、", ", ", + "「", "\"", "」", "\"", "!", "!", "?", "?") + +// Messages is the table of lang for the page (web.json): the page's own strings with their {name} placeholders. +// Empty for Chinese. +func Messages(lang string) map[string]string { + out := map[string]string{} + if lang == Chinese { + return out + } + b, err := localeFS.ReadFile(path.Join("locales", lang, "web.json")) + if err != nil { + return out + } + var raw map[string]*string + if json.Unmarshal(b, &raw) != nil { + return out + } + for k, v := range raw { + if v != nil && *v != "" { + out[k] = *v + } + } + return out +} + +// HasHan reports whether s contains a Chinese character. +func HasHan(s string) bool { + for _, r := range s { + if unicode.Is(unicode.Han, r) { + return true + } + } + return false +} + +var ( + codesOnce sync.Once + codes []string +) + +// tableCodes are the languages with a folder under locales, sorted. +func tableCodes() []string { + codesOnce.Do(func() { + entries, _ := fs.ReadDir(localeFS, "locales") + for _, e := range entries { + if e.IsDir() { + codes = append(codes, e.Name()) + } + } + sort.Strings(codes) + }) + return codes +} + +var ( + catalogsMu sync.Mutex + catalogs = map[string]*catalog{} +) + +func catalogFor(lang string) *catalog { + catalogsMu.Lock() + defer catalogsMu.Unlock() + if c, ok := catalogs[lang]; ok { + return c + } + entries, err := loadTable(lang) + var c *catalog + if err == nil && len(entries) > 0 { + c = newCatalog(entries) + } + catalogs[lang] = c + return c +} + +// loadTable reads every locales//*.json; null and "" values are left out. +func loadTable(lang string) (map[string]string, error) { + dir := path.Join("locales", lang) + entries, err := fs.ReadDir(localeFS, dir) + if err != nil { + return nil, err + } + out := map[string]string{} + for _, e := range entries { + // web.json is the page's (Messages): its labels may say a word differently from the messages of the back end. + if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") || e.Name() == "web.json" { + continue + } + b, err := localeFS.ReadFile(path.Join(dir, e.Name())) + if err != nil { + return nil, err + } + var raw map[string]*string + if err := json.Unmarshal(b, &raw); err != nil { + return nil, err + } + for k, v := range raw { + if v != nil && *v != "" { + out[k] = *v + } + } + } + return out, nil +} + +// capitalize starts a translation with a capital letter when the source starts with a Chinese word: tables write +// words used inside other messages in lower case ("关机" → "shutting down"), which then also serve on their own. +func capitalize(src, out string) string { + s := strings.TrimLeft(src, " \t\n") + r, _ := utf8.DecodeRuneInString(s) + if !unicode.Is(unicode.Han, r) { + return out + } + lead := len(out) - len(strings.TrimLeft(out, " \t\n")) + o, n := utf8.DecodeRuneInString(out[lead:]) + if !unicode.IsLower(o) { + return out + } + return out[:lead] + string(unicode.ToUpper(o)) + out[lead+n:] +} diff --git a/internal/i18n/json.go b/internal/i18n/json.go new file mode 100644 index 00000000..ad953b34 --- /dev/null +++ b/internal/i18n/json.go @@ -0,0 +1,134 @@ +package i18n + +import ( + "bytes" + "encoding/json" + "reflect" + "strings" +) + +// textKeys hold text for people wherever they appear in a result. +var textKeys = map[string]bool{ + "message": true, "advice": true, "msg": true, "warnings": true, "notes": true, "notices": true, "text": true, + "summary": true, "problems": true, "instructions": true, "errors": true, "description": true, "help": true, + "caption": true, "label": true, "hint": true, "privacy_note": true, "not_updatable_reason": true, "error": true, +} + +// listTextKeys hold text for people in the elements of textLists arrays (check items, components), where title / +// name / reason are labels rather than the user's own names. +var ( + listTextKeys = map[string]bool{"title": true, "name": true, "reason": true} + textLists = map[string]bool{"items": true, "components": true} +) + +// machineKeys are never translated, whatever they hold. +var machineKeys = map[string]bool{"details": true, "code": true} + +func isTextKey(k string) bool { + return textKeys[k] || strings.HasSuffix(k, "_error") || strings.HasSuffix(k, "_errors") || + strings.HasSuffix(k, "_note") || strings.HasSuffix(k, "_notes") +} + +// LocalizeJSON translates the text fields of a JSON value (message, advice, warnings …, see textKeys) into lang. In +// Chinese, or when data is not JSON, it is data itself; otherwise re-encoded (key order may change, numbers kept). +func LocalizeJSON(lang string, data []byte) []byte { + if lang == Chinese || !hasNonASCII(data) { + return data + } + dec := json.NewDecoder(bytes.NewReader(data)) + dec.UseNumber() + var v any + if dec.Decode(&v) != nil { + return data + } + v = localizeValue(lang, v, false, false) + var buf bytes.Buffer + enc := json.NewEncoder(&buf) + enc.SetEscapeHTML(false) + if enc.Encode(v) != nil { + return data + } + out := buf.Bytes() + if !bytes.HasSuffix(data, []byte("\n")) { + out = bytes.TrimSuffix(out, []byte("\n")) + } + return out +} + +// Localize is a copy of v (a result struct, or a pointer to one) with the text fields LocalizeJSON translates +// translated, for formatting it for people; v itself when lang is Chinese or the copy cannot be made. The copy may +// share slices and pointers with v and change them: only for a result that is printed and then dropped. +func Localize(lang string, v any) any { + if lang == Chinese || v == nil { + return v + } + data, err := json.Marshal(v) + if err != nil { + return v + } + out := LocalizeJSON(lang, data) + if bytes.Equal(out, data) { + return v + } + t := reflect.TypeOf(v) + ptr := t.Kind() == reflect.Pointer + if ptr { + t = t.Elem() + } + cp := reflect.New(t) + // Fields json leaves out (json:"-", unexported) would be lost: start from the original. + if ptr { + if reflect.ValueOf(v).IsNil() { + return v + } + cp.Elem().Set(reflect.ValueOf(v).Elem()) + } else { + cp.Elem().Set(reflect.ValueOf(v)) + } + if json.Unmarshal(out, cp.Interface()) != nil { + return v + } + if ptr { + return cp.Interface() + } + return cp.Elem().Interface() +} + +func localizeValue(lang string, v any, text, listElem bool) any { + switch x := v.(type) { + case string: + if text { + return Translate(lang, x) + } + return x + case []any: + for i, e := range x { + x[i] = localizeValue(lang, e, text, false) + } + return x + case map[string]any: + for k, e := range x { + if machineKeys[k] { + continue + } + if arr, ok := e.([]any); ok && textLists[k] { + for i, el := range arr { + arr[i] = localizeValue(lang, el, false, true) + } + continue + } + x[k] = localizeValue(lang, e, isTextKey(k) || listElem && listTextKeys[k], false) + } + return x + } + return v +} + +func hasNonASCII(b []byte) bool { + for _, c := range b { + if c >= 0x80 { + return true + } + } + return false +} diff --git a/internal/i18n/locales/en/adb.json b/internal/i18n/locales/en/adb.json new file mode 100644 index 00000000..73c2d0bd --- /dev/null +++ b/internal/i18n/locales/en/adb.json @@ -0,0 +1,55 @@ +{ + "%s 上 %s 在 %.0f 秒内没有上线": "On %s, %s did not come online within %.0f s", + "%s 回的 %s 读不全: %w": "%s replied with a %s that could not be read in full: %w", + "%s 已重新登记到私有 adb server(用时 %.0f ms)": "%s re-registered with the private adb server (took %.0f ms)", + "%s 拒绝了 %s: %s %s": "%s rejected %s: %s %s", + "%s 没有回 %s: %w": "%s did not reply to %s: %w", + "%s 重新登记后的收尾失败: %v": "Cleanup after re-registering %s failed: %v", + "ModAVD %s adb server(端口 %d)%.0f 秒内没监听上%s": "ModAVD %s adb server (port %d) was not listening within %.0f s%s", + "ModAVD %s adb server(端口 %d,pid %d,%s 起来的)%s%s": "ModAVD %s adb server (port %d, pid %d, started at %s) %s%s", + "ModAVD 的%s adb 端口 %d 被 %s(PID %d)占用,%v。请在 %s 里把 %s 改成一个没被占用的端口(不能用 5037 和各实例的控制台 / adb / gRPC 端口,也不能和 %s 相同),或者先关掉占用它的程序": "The %s adb port %d of ModAVD is in use by %s (PID %d): %v. In %s change %s to a free port (not 5037 or the console / adb / gRPC port of any instance, and not the same as %s), or close the program using it first", + "adb %s 已取消": "adb %s canceled", + "adb %s 超时(%.0f 秒)": "adb %s timed out (%.0f s)", + "adb 端口 %d 上不是这台实例的模拟器,不替它登记": "The emulator on adb port %d is not this instance's; not registering it for the instance", + "不认识的程序": "an unknown program", + "关机前已向%s 登记 %s(用时 %.0f ms)": "Before shutdown, registered with %s: %s (took %.0f ms)", + "创建私有 adb 的 AVD 目录失败: %v": "Failed to create the AVD folder for the private adb: %v", + "向 %s 发送 %s 失败: %w": "Failed to send to %s (%s): %w", + "向 %s 发送登记失败: %v": "Failed to send the registration to %s: %v", + "向%s 登记 %s 失败: %v": "Registering with %s failed for %s: %v", + "启动 ModAVD %s adb server(端口 %d)": "Starting ModAVD %s adb server (port %d)", + "启动 ModAVD %s adb server(端口 %d)失败: %s": "Starting ModAVD %s adb server (port %d) failed: %s", + "它不是 adb": "it is not adb", + "已取消": "Canceled", + "已经退出了": "has exited", + "控制台 %d 命令 %s 超时": "Console %d: command %s timed out", + "控制台 %d 没有就绪: %s": "Console %d is not ready: %s", + "控制台 %d 鉴权失败: %s": "Console %d: authentication failed: %s", + "控制台命令 %s 失败: %s": "Console command %s failed: %s", + "新起的私有 adb server": "a newly started private adb server", + "无效的模拟器归属文件": "Invalid emulator ownership file", + "无法确认它是这个根目录的 adb": "cannot confirm it is the adb of this root folder", + "无法运行 adb: %v": "Cannot run adb: %v", + "模拟器归属文件在读取时变化": "The emulator ownership file changed while being read", + "私有": "private", + "私有 adb server": "the private adb server", + "私有 adb server(端口 %d)%.0f 秒内没来得及登记 %s": "The private adb server (port %d) had no time to register %s within %.0f s", + "私有 adb server(端口 %d)%.0f 秒内没起来": "The private adb server (port %d) did not start within %.0f s", + "私有 adb server(端口 %d)上没有 %s,关机前替它登记": "The private adb server (port %d) does not have %s; registering it before shutdown", + "私有 adb server(端口 %d)上没有 %s,按 adb 端口 %d 重新登记": "The private adb server (port %d) does not have %s; re-registering it by adb port %d", + "端口 %d 上的 adb server 在应答,系统的 TCP 监听表里却看不到它(这台电脑的监听表不可靠,不影响使用)": "The adb server on port %d is answering, but the system TCP listener table does not show it (this computer's listener table is unreliable; this does not affect use)", + "系统的 TCP 监听表里端口 %d 的状态值是 %d(不是 LISTEN 的 2),照样算在监听": "In the system TCP listener table, port %d has state value %d (not 2, which is LISTEN); counting it as listening anyway", + "脚本专用": "script-only", + "读不出系统的 TCP 监听表: %v": "Cannot read the system TCP listener table: %v", + "还在,但不再监听": "is still running but no longer listening", + "连不上 %s: %v": "Cannot connect to %s: %v", + "连不上 %s: %w": "Cannot connect to %s: %w", + "连不上控制台 %d: %v": "Cannot connect to console %d: %v", + "连接 %s 超时(%.0f 秒)": "Connecting to %s timed out (%.0f s)", + "重新登记 %s 后 %.0f 秒仍未上线": "%s was still not online %.0f s after re-registering", + "重新登记 %s 失败: %v": "Re-registering %s failed: %v", + "重新登记后的收尾(重起客体日志落盘)%.0f 秒内没做完,不再等": "The cleanup after re-registering (restarting guest log flushing) did not finish within %.0f s; not waiting any longer", + "长度 %q 不是十六进制": "length %q is not hexadecimal", + ";adb 自己的日志(logs\\%s)最后几行:\n %s": "; last lines of adb's own log (logs\\%s):\n %s", + ";adb 自己的日志(logs\\%v)里没有记录": "; adb's own log (logs\\%v) has no entries" +} diff --git a/internal/i18n/locales/en/apk.json b/internal/i18n/locales/en/apk.json new file mode 100644 index 00000000..3f49da92 --- /dev/null +++ b/internal/i18n/locales/en/apk.json @@ -0,0 +1,20 @@ +{ + "%s 里的 AndroidManifest.xml 太大": "AndroidManifest.xml in %s is too large", + "%s 里的 AndroidManifest.xml 太大(%d 字节)": "AndroidManifest.xml in %s is too large (%d bytes)", + "%v 不是 APK(不是 zip 文件)": "%v is not an APK (not a zip file)", + "%v 不是 APK(里面没有 AndroidManifest.xml)": "%v is not an APK (no AndroidManifest.xml inside)", + "APK 文件不存在: %v": "APK file does not exist: %v", + "versionCode %q 不是整数": "versionCode %q is not an integer", + "不是二进制 XML": "Not binary XML", + "偏移 %d 越界": "Offset %d is out of range", + "偏移 %d 长度 %d 越界": "Offset %d with length %d is out of range", + "字符串 %d 不是合法的 UTF-16": "String %d is not valid UTF-16", + "字符串下标 %d 越界(共 %d 个)": "String index %d is out of range (%d in total)", + "打不开 APK 文件: %v": "Cannot open APK file: %v", + "数据块(偏移 %d)大小 %d 不对": "Chunk (offset %d) has a wrong size %d", + "没有找到开始标签": "No start tag found", + "第一个开始标签是 <%s>,不是 ": "The first start tag is <%s>, not ", + "读不出 %s 的包名和版本号: %v": "Cannot read the package name and version of %s: %v", + "读不出 %v 里的 AndroidManifest.xml": "Cannot read AndroidManifest.xml in %v", + "资源 ID 表头大小 %d 不对": "Resource ID table header has a wrong size %d" +} diff --git a/internal/i18n/locales/en/appproxy.json b/internal/i18n/locales/en/appproxy.json new file mode 100644 index 00000000..3424b11c --- /dev/null +++ b/internal/i18n/locales/en/appproxy.json @@ -0,0 +1,74 @@ +{ + "%s 上的程序既不说 SOCKS5,也不说 HTTP 代理(%v)": "The program at %s speaks neither SOCKS5 nor HTTP proxy (%v)", + "%s 在名单里出现了两次": "%s appears twice in the list", + "%v 不在名单里": "%v is not in the list", + "DNS 报文格式不对": "Malformed DNS message", + "DNS 查询超时": "DNS query timed out", + "DNS 要写成 IPv4 地址加端口(比如 %s):%q": "DNS must be an IPv4 address with a port (for example %s): %q", + "DNS 连接上等着的查询太多": "Too many queries waiting on the DNS connection", + "SOCKS5 地址类型 %d 不认识": "Unknown SOCKS5 address type %d", + "TCP 端口 %d 用不了:%v": "TCP port %d is unavailable: %v", + "UDP 端口 %d 用不了:%v": "UDP port %d is unavailable: %v", + "config.json 读不懂:%v": "Cannot parse config.json: %v", + "不支持 %s 代理,只支持 socks5:// 和 http://": "Unsupported %s proxy; only socks5:// and http:// are supported", + "不支持要账号密码的代理": "Proxies that need a username and password are not supported", + "不是代理地址:%q": "Not a proxy address: %q", + "不是安卓包名:%q": "Not an Android package name: %q", + "主机不可达": "Host unreachable", + "代理不支持这个命令": "The proxy does not support this command", + "代理不支持这种地址": "The proxy does not support this kind of address", + "代理不转发 UDP": "The proxy does not forward UDP", + "代理内部出错": "Proxy internal error", + "代理地址前面要写类型:socks5://… 或 http://…": "The proxy address needs a type in front: socks5://... or http://...", + "代理地址只写「类型://地址:端口」:%q": "Write the proxy address only as \"type://address:port\": %q", + "代理地址要写 IPv4 地址或 localhost:%q": "The proxy address must be an IPv4 address or localhost: %q", + "代理地址要写 IPv4 地址:%q": "The proxy address must be an IPv4 address: %q", + "代理地址要带端口(1–65535):%q": "The proxy address needs a port (1-65535): %q", + "代理拒绝:%v": "Proxy refused: %v", + "代理的 UDP 转发地址 %s 用不了": "The proxy's UDP relay address %s is unusable", + "代理的 UDP 转发地址是域名 %s,不支持": "The proxy's UDP relay address is a domain name (%s), which is not supported", + "代理的回应头太长": "The proxy response header is too long", + "代理的回应行太长": "The proxy response line is too long", + "代理的规则不让连": "The proxy rules do not allow the connection", + "代理要账号密码,这一版只支持不要认证的代理": "The proxy needs a username and password; this version only supports proxies without authentication", + "代理选了认证方式 %d,这一版只支持不要认证的代理": "The proxy chose authentication method %d; this version only supports proxies without authentication", + "停止,撤掉规则": "Stopping, removing the rules", + "写不了状态:%v": "Cannot write the state: %v", + "名单里最多 %d 个应用": "The list can hold at most %d apps", + "名单里有 %d 个应用,最多 %d 个": "The list has %d apps, at most %d", + "启动(%s,modavd %s):%s,%d 个应用": "Starting (%s, modavd %s): %s, %d apps", + "实例里连宿主要用 %s,代理地址记成了 %s": "Inside the instance the host is reached at %s, but the proxy address was recorded as %s", + "对方拒绝连接": "The other side refused the connection", + "已关闭": "Closed", + "已经有一个在跑": "One is already running", + "打不开锁文件:%v": "Cannot open lock file: %v", + "找不到本机的代理设置": "Cannot find this computer's proxy settings", + "换配置:%s,%d 个应用": "Config changed: %s, %d apps", + "新配置用不了,还用原来的:%v": "The new config is unusable; keeping the old one: %v", + "用法:modavd-proxyd start|stop|status|version": "Usage: modavd-proxyd start|stop|status|version", + "盯不了 %s(%v),只靠每 10 秒查一次": "Cannot watch %s (%v); checking only every 10 seconds", + "经代理向 %s 发的 DNS 查询 %s 内没有回音": "No reply to the DNS query sent through the proxy to %s within %s", + "经代理回来的不是 DNS 回答": "What came back through the proxy is not a DNS answer", + "经代理连 %s 失败:%s": "Failed to connect to %s through the proxy: %s", + "经代理连 %s 失败:%w": "Failed to connect to %s through the proxy: %w", + "网络不可达": "Network unreachable", + "装的应用变了,名单里的 uid 现在是 %v": "Installed apps changed; the uid in the list is now %v", + "要先给代理地址": "A proxy address is needed first", + "规则少了(%s),补上": "Rules are missing (%s); restoring them", + "规则挂不上:%v": "Cannot install the rules: %v", + "读不了 %s,不知道名单里的应用是哪个 uid:%v": "Cannot read %s, so cannot tell the uid of the app in the list: %v", + "读不了 %s:%v": "Cannot read %s: %v", + "读不了配置:%v": "Cannot read the config: %v", + "起不来:%v": "Cannot start: %v", + "超时": "Timed out", + "这个端口说的不是 HTTP": "This port does not speak HTTP", + "这个端口说的不是 SOCKS5": "This port does not speak SOCKS5", + "连不上 %s:%s(代理软件开着吗?端口对吗?)": "Cannot connect to %s: %s (is the proxy software running? is the port right?)", + "连不上代理 %s:%v": "Cannot connect to proxy %s: %v", + "连不上代理的 UDP 转发地址 %s:%v": "Cannot connect to the proxy's UDP relay address %s: %v", + "连接太多": "Too many connections", + "连接超时": "Connection timed out", + "配置版本是 %d,这个版本的 modavd-proxyd 只认 %d": "The config version is %d, but this version of modavd-proxyd only accepts %d", + "错误码 %d": "Error code %d", + "(之前 10 秒里还有 %d 条类似的没记)": "(%d similar messages in the previous 10 seconds were not logged)" +} diff --git a/internal/i18n/locales/en/avd.json b/internal/i18n/locales/en/avd.json new file mode 100644 index 00000000..f07a44fd --- /dev/null +++ b/internal/i18n/locales/en/avd.json @@ -0,0 +1,29 @@ +{ + "%s 读不出:%s": "Cannot read %s: %s", + "ModAVD 实例 %d 不存在": "ModAVD instance %d does not exist", + "ModAVD 实例已满(端口段 %d–%d 最多 9 台)": "No free ModAVD instance slot (port range %d-%d holds at most 9)", + "ModAVD 的 CPU 核数只能选 %v": "ModAVD CPU cores must be one of %v", + "ModAVD 的内存只能选 %v": "ModAVD memory must be one of %v", + "内存要写成 6144、6144M 或 6G,收到「%s」": "Memory must be written as 6144, 6144M or 6G, got \"%s\"", + "写 %s 失败:%v": "Failed to write %s: %v", + "写不了 %s:目录 %s 不存在(实例可能刚被删除)": "Cannot write %s: folder %s does not exist (the instance may have just been deleted)", + "分辨率只能选 1080 或 720": "Resolution must be 1080 or 720", + "删除 %s 失败:%v": "Failed to delete %s: %v", + "可能有文件正被占用(实例还开着?);关掉占用它的程序后再试": "A file may be in use (is the instance still running?); close the program using it and try again", + "可能正被别的程序独占;关掉占用它的程序后再试": "It may be locked by another program; close the program using it and try again", + "实例 %s 已存在": "Instance %s already exists", + "实例 %s 的配置读不出": "Cannot read the configuration of instance %s", + "实例标题不能包含换行": "The instance title cannot contain line breaks", + "实例目录 %s 是链接,不能跟着它删除": "Instance folder %s is a link; it will not be deleted through the link", + "实例编号 %d 不可用(只能是 0–9,5 除外)": "Instance number %d is not available (must be 0-9, except 5)", + "帧率只能在 %d–%d 之间": "Frame rate must be between %d and %d", + "建不了目录 %s:%v": "Cannot create folder %s: %v", + "拒绝访问(可能正被别的程序独占)": "Access denied (it may be locked by another program)", + "数据盘上限只能在 %d–%d GB 之间": "The data disk limit must be between %d and %d GB", + "数据盘上限只能改大:实例 %d 现在是 %d GB,不能改成 %d GB": "The data disk limit can only be increased: instance %d is %d GB now and cannot be changed to %d GB", + "数据盘只能二选一:自动扩盘,或者指定大小": "Choose one for the data disk: automatic size, or a fixed size", + "文件不存在": "File does not exist", + "替换 %s 失败:%v": "Failed to replace %s: %v", + "请手动删除这个链接和它指向的数据": "Delete this link and the data it points to by hand", + "读不了实例目录 %s:%v": "Cannot read instance folder %s: %v" +} diff --git a/internal/i18n/locales/en/bosskey.json b/internal/i18n/locales/en/bosskey.json new file mode 100644 index 00000000..61ff6434 --- /dev/null +++ b/internal/i18n/locales/en/bosskey.json @@ -0,0 +1,16 @@ +{ + "%q 不是 Ctrl、Alt、Shift,只能放在最后": "%q is not Ctrl, Alt or Shift, so it can only go last", + "Alt 写了两次": "Alt is given twice", + "Ctrl 写了两次": "Ctrl is given twice", + "Shift 写了两次": "Shift is given twice", + "Win 的组合 Windows 自己留着用,不能当老板键": "Win combinations are reserved by Windows and cannot be a boss key", + "不认识按键 %q": "Unknown key %q", + "写成 Ctrl+Alt+Shift+1 这样:Ctrl、Alt、Shift 至少带一个,最后是一个数字、字母、F1–F24、Num0–Num9 等按键;不要老板键写 none": "Write it like Ctrl+Alt+Shift+1: include at least one of Ctrl, Alt, Shift, ending with a key such as a digit, a letter, F1-F24 or Num0-Num9; write none for no boss key", + "实例 %d 的 %s 不是字符串,当作不要老板键": "%s of instance %d is not a string; treated as no boss key", + "实例 %d 的老板键 %q 不对,当作不要老板键": "The boss key %q of instance %d is invalid; treated as no boss key", + "有空的一段": "There is an empty part", + "缺少 Ctrl、Alt、Shift 以外的那个按键": "The key other than Ctrl, Alt and Shift is missing", + "老板键 %q 不对:%s": "Boss key %q is invalid: %s", + "老板键是空的": "The boss key is empty", + "至少要带 Ctrl、Alt、Shift 中的一个": "Include at least one of Ctrl, Alt, Shift" +} diff --git a/internal/i18n/locales/en/cli.json b/internal/i18n/locales/en/cli.json new file mode 100644 index 00000000..e5490eed --- /dev/null +++ b/internal/i18n/locales/en/cli.json @@ -0,0 +1,460 @@ +{ + "\n全局选项(写在命令前后都行;adb、shell 要写在命令本身前面):\n --root <目录> ModAVD 根目录;不给就用环境变量 MODAVD_ROOT,再不行用 modavd.exe 所在目录或它的上一级\n --json stdout 只输出一行 JSON:{\"ok\":true,\"data\":…} 或 {\"ok\":false,\"error\":{\"code\",\"message\",\"advice\"}};\n 日志以每行一个 JSON 对象写到 stderr({\"time\",\"level\",\"msg\"},可能多出字段,\n 比如 update 的进度行带 \"progress\")\n --quiet 只输出警告和错误日志\n --verbose 输出调试日志和错误原因\n\n 写成 3 或 mas_3(0–9,5 除外)。内存写成 6144、6144M 或 6G。\n\n退出码:0 成功,1 内部错误,2 用法或参数不对、未同意许可协议(license_declined),3 实例不存在,4 根目录没就绪、检查没通过或不支持,\n5 实例忙、已存在或端口被占,6 超时,7 启动失败,8 已取消(Ctrl+C),9 更新或组件下载不可用、校验未通过,或代理不可用,\n10 电脑内存不足、模拟器起不来(insufficient_memory)。\n例外:shell 不带 --json 时是命令自己的退出码;adb 是 adb 的退出码;stop --all 有失败时是第一个失败的退出码。\n\n运行 modavd help <命令> 查看某个命令的说明和选项。\n": "\nGlobal options (before or after the command; for adb and shell, put them before the command itself):\n --root ModAVD root folder; if omitted, the MODAVD_ROOT environment variable, then the folder of modavd.exe or its parent\n --json stdout gets a single line of JSON: {\"ok\":true,\"data\":…} or {\"ok\":false,\"error\":{\"code\",\"message\",\"advice\"}};\n logs go to stderr as one JSON object per line ({\"time\",\"level\",\"msg\"}, possibly with extra fields,\n e.g. progress lines of update carry \"progress\")\n --quiet only log warnings and errors\n --verbose log debug messages and error causes\n\n is written as 3 or mas_3 (0-9, except 5). Memory is written as 6144, 6144M or 6G.\n\nExit codes: 0 success, 1 internal error, 2 bad usage or arguments, or license not accepted (license_declined), 3 instance not found, 4 root folder not ready, check failed or unsupported,\n5 instance busy, already exists or port in use, 6 timeout, 7 start failed, 8 canceled (Ctrl+C), 9 update or component download unavailable, verification failed, or proxy unavailable,\n10 not enough memory on this PC, the emulator cannot start (insufficient_memory).\nExceptions: shell without --json returns the command's own exit code; adb returns adb's exit code; stop --all with failures returns the first failure's exit code.\n\nRun modavd help for a command's description and options.\n", + "\n用法:%s\n\n命令:\n": "\nUsage: %s\n\nCommands:\n", + "\n选项:": "\nOptions:", + " 1. 自动(googledownloads_cn、tencent、google,按顺序尝试)": " 1. Automatic (googledownloads_cn, tencent, google, tried in order)", + " 十六进制:%s\n": " Hex: %s\n", + " 十进制:%s\n": " Decimal: %s\n", + " 原来不完整的目录改名为 %s,确认没用后可以自己删掉\n": " The previously incomplete folder was renamed to %s; delete it yourself once you are sure it is not needed\n", + " 原来就有、校验无误留下的:%s\n": " Already present and verified, kept: %s\n", + " 已打断新建初始化,用 modavd create --resume %d 重做\n": " Interrupted the initial setup of the new instance; redo it with modavd create --resume %d\n", + " 建议:%s\n": " Suggestion: %s\n", + " 不全,source.properties 不对": " incomplete, source.properties is wrong", + " 不全,缺 %v": " incomplete, missing %v", + " 未安装": " not installed", + "%s 只用于 components fetch": "%s is only for components fetch", + "%s已开机:开机 %.1f 秒,合计 %.1f 秒\n": "%sStarted: boot %.1f s, total %.1f s\n", + "%s本来就在运行,已重新做开机后的设置(%.1f 秒)\n": "%sWas already running; redid the post-boot setup (%.1f s)\n", + "%s没有改动\n": "%sNo changes\n", + "%s,上次开机剩余 %.1f GB": "%s, %.1f GB left at the last start", + "%v 软件渲染(没有可用的显卡驱动)": "%v software rendering (no usable graphics driver)", + "%v(可选%v)": "%v (optional%v)", + "%v(指定大小)": "%v (fixed size)", + "%v(私有 adb server 上)": "%v (on the private adb server)", + "--%s 要在 1–%.0f 秒之间,收到 %d": "--%s must be between 1 and %.0f seconds, got %d", + "--after-pid 要给进程号,收到 %d": "--after-pid needs a process ID, got %d", + "--after-pid、--reopen、--reopen-arg、--handoff-id 只能和 install 一起用": "--after-pid, --reopen, --reopen-arg and --handoff-id can only be used with install", + "--data-gb 只能是 auto 或 %d–%d 的整数(GB),收到「%s」": "--data-gb must be auto or an integer from %d to %d (GB), got \"%s\"", + "--diagnostics 只能是 on 或 off": "--diagnostics must be on or off", + "--handoff-id 要和 --reopen 一起用": "--handoff-id must be used with --reopen", + "--package 和 --sha256 只用于 update prepare 或 install": "--package and --sha256 are only for update prepare or install", + "--reopen 要给程序的完整路径,收到「%s」": "--reopen needs the full path of a program, got \"%s\"", + "--reopen-arg 要和 --reopen 一起用": "--reopen-arg must be used with --reopen", + "--resume 只重做初始化,不能再给 --%s": "--resume only redoes the initial setup; --%s cannot be given with it", + "--sound 只能是 on 或 off": "--sound must be on or off", + "--source、--cdk-dpapi 不能和 recover 一起用": "--source and --cdk-dpapi cannot be used with recover", + "--test-free-space-mb 不能是负数": "--test-free-space-mb cannot be negative", + "--timeout 要给大于 0 的秒数,收到 %d": "--timeout needs a number of seconds greater than 0, got %d", + "--window 和 --headless 只能给一个": "--window and --headless cannot both be given", + "0.3.0 起没有重启:先 modavd stop ,再 modavd start (要窗口加 --window)": "There is no restart since 0.3.0: run modavd stop , then modavd start (add --window for a window)", + " [--] ": " [--] ", + " [--timeout 秒] <命令...>": " [--timeout SECONDS] ", + " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--data-gb auto|N] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key 组合|none]": " [--title T] [--memory M] [--cpu N] [--fps F] [--resolution 1080|720] [--data-gb auto|N] [--language host|preserve|LANG] [--timezone host|preserve|IANA] [--diagnostics on|off] [--sound on|off] [--boss-key COMBO|none]", + " [on|off|test] [--server URL|auto] [--add 包名] [--remove 包名] [--apps 包名]": " [on|off|test] [--server URL|auto] [--add PACKAGE] [--remove PACKAGE] [--apps PACKAGE]", + "APK 路径": "APK path", + "ARM64 商店文件已准备;当前 macOS 版本尚未开放实例内安装与移除": "ARM64 Store files are ready; this macOS version does not yet support installing or removing them in an instance", + "DNS:%s(经代理用 TCP 查)\n": "DNS: %s (resolved over TCP through the proxy)\n", + "Google Play 商店的五个文件已经齐全、校验无误,没有改动(给的文件也核对过了)": "The five Google Play Store files are complete and verified; nothing changed (the files you gave were checked too)", + "Google Play 版镜像的压缩包": "Google Play system image archive", + "HTTP 代理": "HTTP proxy", + "MCP 服务已就绪,根目录 %s": "MCP server is ready, root folder %s", + "Mirror 酱(CDK %v)": "MirrorChyan (CDK %v)", + "ModAVD 实例 %d 关机失败: %s": "ModAVD instance %d failed to shut down: %s", + "ModAVD:%s,根目录 %s\n": "ModAVD: %s, root folder %s\n", + "SDK:%s(mas-avd.json 的 sdkRoot)\n": "SDK: %s (sdkRoot in mas-avd.json)\n", + "UDP:不通,名单里的应用只能用 TCP;换成代理软件的 SOCKS5 或混合端口就都能用": "UDP: not working, apps in the list can only use TCP; switch to the SOCKS5 or mixed port of your proxy software and both work", + "UDP:可用": "UDP: available", + "UDP:失败(%v)": "UDP: failed (%v)", + "Windows:host 按宿主界面语言设置一次,preserve 保持安卓语言,或指定 zh-CN、en-US 等语言": "Windows: host sets it once from the host UI language, preserve keeps the Android language, or give a language such as zh-CN or en-US", + "Windows:host 每次冷启动跟随宿主,preserve 沿用原行为,或指定 Asia/Shanghai、Etc/UTC 等 IANA 时区": "Windows: host follows the host on every cold start, preserve keeps the previous behavior, or give an IANA time zone such as Asia/Shanghai or Etc/UTC", + "[--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--language host|preserve|语言] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N": "[--index N] [--title T] [--memory 6G] [--cpu N] [--data-gb auto|N] [--fps 1-60] [--resolution 1080|720] [--language host|preserve|LANG] [--timezone host|preserve|IANA] [--no-bridge] [--timeout 1200] | --resume N", + "[--out-dir 目录] [--stage-dir 目录] [--keep-stage] [--no-explorer]": "[--out-dir DIR] [--stage-dir DIR] [--keep-stage] [--no-explorer]", + "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore <文件或文件夹>…": "[status] | source [auto|googledownloads_cn|tencent|google] | fetch [--accept-license] [--mirror ID] [--mirror-url URL] [--keep-downloads] [--play-store] | import-playstore ...", + "[status|check|prepare|install|recover] [--source github|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V] [--package ZIP --sha256 HEX] [--after-pid PID --reopen 程序 [--reopen-arg 参数]... [--handoff-id ID]]": "[status|check|prepare|install|recover] [--source github|mirrorchyan] [--cdk-dpapi BASE64] [--automas-version V] [--package ZIP --sha256 HEX] [--after-pid PID --reopen PROGRAM [--reopen-arg ARG]... [--handoff-id ID]]", + "[命令]": "[command]", + "adb server:私有 %d,脚本用 %d\n": "adb server: private %d, scripts %d\n", + "adb 参数": "adb arguments", + "adb 地址": "adb address", + "adb 地址:%s\n": "adb address: %s\n", + "adb 地址:%s(私有 adb server 上是 %s)\n": "adb address: %s (%s on the private adb server)\n", + "components %s 只接受一个参数": "components %s takes only one argument", + "components import-playstore 要给文件或文件夹:Google Play 版镜像的压缩包 %v,或者商店的五个文件": "components import-playstore needs a file or folder: the Google Play system image archive %v, or the five Store files", + "components source 最多带一个下载源": "components source takes at most one download source", + "disk 动作 %s 没有实现": "disk action %s is not implemented", + "host|preserve|语言": "host|preserve|LANG", + "install、uninstall 或 verify": "install, uninstall or verify", + "install、uninstall、status 或 gsfid": "install, uninstall, status or gsfid", + "macOS 本地完整更新包": "macOS local full update package", + "modavd %s 已经去掉了": "modavd %s has been removed", + "modavd %s(协议 %d,%s)\n": "modavd %s (protocol %d, %s)\n", + "modavd [--root <目录>] [--json] [--quiet] [--verbose] <命令> [参数]": "modavd [--root ] [--json] [--quiet] [--verbose] [arguments]", + "modavd help <命令> 显示一个命令的说明和选项。": "modavd help shows a command's description and options.", + "modavd 的版本和协议版本": "modavd version and protocol version", + "modavd:ModAVD 实例管理(新建、删除、修改、列出、开机、关机)和 MCP 服务": "modavd: ModAVD instance management (create, delete, change, list, start, shut down) and MCP server", + "on、off 或 status": "on, off or status", + "on、off 或 test": "on, off or test", + "show 或 hide": "show or hide", + "status、check、prepare、install 或 recover": "status, check, prepare, install or recover", + "status、source、fetch 或 import-playstore": "status, source, fetch or import-playstore", + "status(默认)查看组件,和 check 里的组件一样。fetch 补全缺少的 adb 和 Android 15 Google APIs ARM64 系统镜像:先从镜像取待下载组件的 Google 许可协议全文,逐份输入 y 同意才继续,否则不下载归档。默认依次试 googledownloads.cn、腾讯云镜像、dl.google.com,下载约 1.8 GB,中断后再次运行会接着下;校验归档、版本和平台后装进 sdk/,保留执行权限。已经齐全的跳过;不完整的旧目录改名为 <目录>.incomplete-<时间> 留着,不删。SDK 使用中会拒绝补全,请先自行关闭使用它的进程。组件补全后,当前 macOS 版本仍未开放实例创建与启动。--play-store 可选下载 Android 15 Google Play arm64-v8a r9 镜像(约 1.8 GB),校验后只保留商店等五个文件。import-playstore 可导入官方 arm64-v8a-35_r09.zip 或五个文件,按固定大小和摘要检查,不下载。这两项仅准备文件,当前 macOS 版本尚未开放实例内安装与移除。source 查看或修改记住的下载源(auto、googledownloads_cn、tencent、google);--mirror 或 --mirror-url 可覆盖本次选择。--json 时必须给 --accept-license(仅 fetch),表示已同意待下载组件的全部许可协议。退出码:未同意许可是 2(license_declined),未就绪或预检失败是 4,SDK 使用中或正在补全是 5,下载不可用或校验失败是 9。": "status (default) shows the components, same as the components in check. fetch fills in the missing adb and Android 15 Google APIs ARM64 system image: it first gets the Google license text of the components to download from the mirror and asks for y on each one before continuing, otherwise it downloads no archive. By default it tries googledownloads.cn, the Tencent Cloud mirror and dl.google.com in turn; the download is about 1.8 GB and resumes if interrupted; it verifies the archive, version and platform, then installs into sdk/ keeping execute permissions. Components that are already complete are skipped; an incomplete old folder is renamed to .incomplete-