From bad755413bf45243b5d751212050fa97d038a10b Mon Sep 17 00:00:00 2001 From: argszero Date: Sat, 12 Sep 2026 01:55:28 +0800 Subject: [PATCH] fix(ui): translate the remaining user-visible backend errors in English mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ERR_MAP maps the backend's Chinese error strings to English translation keys. Several messages returned on paths a user can actually reach were never wired into it, so English-mode users saw raw Chinese. The clearest case was an orphaned key: err.network was defined in both packs and its Chinese value is exactly the literal api.js passes to mapErr on a network failure, but no ERR_MAP entry referenced it - the translation existed and was unreachable. Covered now (all on paths the console calls): err.network 网络不可用,请检查后端服务是否启动 (api.js network failure) err.emailNotRegistered 该邮箱未注册 (auth/reset_password, forgot-password form) err.raisePending 已有待审批的加额申请,请等待管理员处理 (raise_requests/create) err.raiseHandled 该申请已处理 (raise_requests approve/reject) err.codeSendFail 验证码发送失败,请重试 (auth/login 502) err.modelExists 模型已存在(provider+model 唯一) (admin/models create/patch) err.negativePrice 价格不能为负数 (admin/models create/patch) Six new keys were added to both packs (769 -> 775, ZH == EN); err.network already existed and only needed wiring. Coverage of the 40 production backend error strings goes from 18 to 24. Verified against the true pre-fix baseline (git HEAD), replaying every real message through the real mapErr in EN mode: exactly 7 messages change, all from raw Chinese to English, and 0 regressions - the single merged entry that covers two sources (err.network) is counted once. Controls: zh passthrough, unmatched passthrough, null passthrough, and a wired key still translating. Deliberately NOT covered, to keep this change honest rather than exhaustive: the remaining unmapped strings are defensive validation on URLs/states the console never generates (wallet "type must be..." / ISO-8601 params, sharing "status must be...", admin-models field validators, org field validators, gateway body validators), plus one literal for an expired session that is never displayed. They fail closed as raw Chinese. --- ui/index.html | 10 +++++----- ui/js/i18n.js | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/ui/index.html b/ui/index.html index 957b6c8..d7f7547 100644 --- a/ui/index.html +++ b/ui/index.html @@ -5,7 +5,7 @@ AITokenPool - + @@ -842,9 +842,9 @@

使用模型

- - - - + + + + diff --git a/ui/js/i18n.js b/ui/js/i18n.js index 3b6c110..a151dbb 100644 --- a/ui/js/i18n.js +++ b/ui/js/i18n.js @@ -815,6 +815,12 @@ "err.codeLocked": "验证码错误次数过多,请重新获取", "err.badEmail": "邮箱格式不正确", "err.weakPassword": "密码至少 8 位", + "err.emailNotRegistered": "该邮箱未注册", + "err.modelExists": "模型已存在(provider+model 唯一)", + "err.raisePending": "已有待审批的加额申请,请等待管理员处理", + "err.raiseHandled": "该申请已处理", + "err.codeSendFail": "验证码发送失败,请重试", + "err.negativePrice": "价格不能为负数", }; var EN = { @@ -1601,6 +1607,12 @@ "err.codeLocked": "Too many wrong attempts, please request a new code", "err.badEmail": "Invalid email format", "err.weakPassword": "Password must be at least 8 characters", + "err.emailNotRegistered": "This email is not registered", + "err.modelExists": "Model already exists (provider + model must be unique)", + "err.raisePending": "A raise request is already awaiting approval", + "err.raiseHandled": "This request has already been handled", + "err.codeSendFail": "Failed to send the verification code, please try again", + "err.negativePrice": "Price cannot be negative", }; // 后端中文错误 → en 键(lang=en 时对已知错误做映射;未知原样返回) @@ -1608,8 +1620,12 @@ // 只是为了让人读起来「最具体的在最前」,避免后续插条时又互相遮蔽(如 // 「不存在」遮蔽「验证码不存在或已过期」、「验证码错误」遮蔽「验证码错误次数过多」)。 var ERR_MAP = [ + ["模型已存在(provider+model 唯一)", "err.modelExists"], + ["已有待审批的加额申请,请等待管理员处理", "err.raisePending"], + ["网络不可用,请检查后端服务是否启动", "err.network"], ["该模型暂无可用 key", "err.noAvailableKey"], ["API Key 不存在", "err.keyNotFound"], + ["验证码发送失败,请重试", "err.codeSendFail"], ["验证码不存在或已过期", "err.codeExpired"], ["验证码错误次数过多", "err.codeLocked"], ["密码至少 8 位", "err.weakPassword"], @@ -1618,9 +1634,12 @@ ["key 不存在", "err.keyNotFound"], ["服务器内部错误", "err.serverError"], ["邮箱格式不正确", "err.badEmail"], + ["价格不能为负数", "err.negativePrice"], ["点数余额不足", "err.insufficient"], ["请求过于频繁", "err.rateLimit"], ["该邮箱已注册", "err.emailTaken"], + ["该邮箱未注册", "err.emailNotRegistered"], + ["该申请已处理", "err.raiseHandled"], ["邮箱未验证", "err.emailUnverified"], ["验证码错误", "err.badCode"], ["余额不足", "err.insufficient"],