Skip to content

fix(auth): localize public auth messages - #4800

Open
neow021 wants to merge 1 commit into
QuantumNous:mainfrom
neow021:fix/auth-public-i18n
Open

fix(auth): localize public auth messages#4800
neow021 wants to merge 1 commit into
QuantumNous:mainfrom
neow021:fix/auth-public-i18n

Conversation

@neow021

@neow021 neow021 commented May 12, 2026

Copy link
Copy Markdown
Contributor

📝 变更描述 / Description

公开认证流程里仍有几处用户可见中文或固定英文文案,包括邮箱验证码、密码重置邮件、邮箱限制提示、密码重置链接错误、邮箱验证码限流提示,以及 Turnstile 校验错误。

这个 PR 将这些文案接入后端 i18n:

  • SendEmailVerification 使用 i18n 返回邮箱参数/域名/别名/占用错误,并生成本地化验证码邮件主题和正文。
  • SendPasswordResetEmail 使用 i18n 生成密码重置邮件主题和正文。
  • ResetPassword 使用 i18n 返回无效参数和重置链接无效/过期错误。
  • 邮箱验证码限流 middleware 和 Turnstile middleware 使用已支持的 common.TranslateMessage 返回本地化错误。

Part of #3490. Related to #1906.

🚀 变更类型 / Type of change

  • 🐛 Bug 修复 (Bug fix) - 请关联对应 Issue,避免将设计取舍、理解偏差或预期不一致直接归类为 bug
  • ✨ 新功能 (New feature) - 重大特性建议先通过 Issue 沟通
  • ⚡ 性能优化 / 重构 (Refactor)
  • 📝 文档更新 (Documentation)

🔗 关联任务 / Related Issue

✅ 提交前检查项 / Checklist

  • 人工确认: 我已亲自整理并撰写此描述,没有直接粘贴未经处理的 AI 输出。
  • 非重复提交: 我已搜索现有的 IssuesPRs,确认不是重复提交。
  • Bug fix 说明: 若此 PR 标记为 Bug fix,我已提交或关联对应 Issue,且不会将设计取舍、预期不一致或理解偏差直接归类为 bug。
  • 变更理解: 我已理解这些更改的工作原理及可能影响。
  • 范围聚焦: 本 PR 未包含任何与当前任务无关的代码改动。
  • 本地验证: 已在本地运行并通过测试或手动验证,维护者可以据此复核结果。
  • 安全合规: 代码中无敏感凭据,且符合项目代码规范。

📸 运行证明 / Proof of Work

Base: QuantumNous/new-api@ba474393

本地验证使用与 Dockerfile 一致的 Go 镜像:

docker run --rm -v "$PWD":/src -w /src golang:1.26.1-alpine gofmt -w controller/misc.go i18n/keys.go middleware/email-verification-rate-limit.go middleware/turnstile-check.go
docker run --rm -v "$PWD":/src -w /src -e GOCACHE=/tmp/go-cache -e GOMODCACHE=/tmp/go-mod-cache golang:1.26.1-alpine go test ./controller ./middleware ./i18n
ruby -e 'require "yaml"; ARGV.each { |f| YAML.load_file(f) }' i18n/locales/en.yaml i18n/locales/zh-CN.yaml i18n/locales/zh-TW.yaml\n```\n\n验证结果:\n\n- `gofmt` 已执行。\n- `go test ./controller ./middleware ./i18n` 通过。\n- `en/zh-CN/zh-TW` locale YAML 解析通过。\n- 新增 auth i18n keys 在三份 locale 文件中保持一致。\n- `git diff --check` 通过。\n\n补充说明:全量 `go test ./...` 在当前 upstream main 上仍失败,失败点与本 PR 无关:根包缺少 `web/classic/dist` embed 目录,且 `relay/channel/claude``relay/helper` 现有测试有失败。相关包验证已单独通过。\n\n变更范围:\n\n- `controller/misc.go`\n- `middleware/email-verification-rate-limit.go`\n- `middleware/turnstile-check.go`\n- `i18n/keys.go`\n- `i18n/locales/{en,zh-CN,zh-TW}.yaml`\n

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

* **New Features**
  * Added multi-language support for authentication workflows, including email verification and password reset processes.
  * Authentication error messages, email content, and security verification notifications now display in English, Simplified Chinese, and Traditional Chinese based on user locale.
  * Rate limiting messages and security verification feedback are now localized.

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/QuantumNous/new-api/pull/4800)

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: aa2ec517-fb5c-4616-a822-e13895522a86

📥 Commits

Reviewing files that changed from the base of the PR and between 19fc384 and a9784e2.

📒 Files selected for processing (7)
  • controller/misc.go
  • i18n/keys.go
  • i18n/locales/en.yaml
  • i18n/locales/zh-CN.yaml
  • i18n/locales/zh-TW.yaml
  • middleware/email-verification-rate-limit.go
  • middleware/turnstile-check.go

Walkthrough

Email verification, password reset, and Turnstile validation workflows are refactored to use localized i18n messages. Message keys are defined, handlers and middleware are updated to translate errors and email templates, and translations for English and Simplified/Traditional Chinese locales are provided.

Changes

Authentication Message Internationalization

Layer / File(s) Summary
Message key contract definition
i18n/keys.go
Exports 18 message key constants for email validation, email verification content, password reset content, rate-limit wait/retry, and Turnstile token failures.
Handler i18n integration
controller/misc.go
Email verification and password reset handlers use common.ApiErrorI18n for validation errors and i18n.T(...) templates for email subjects and HTML bodies; imports updated to include i18n.
Middleware error message translation
middleware/email-verification-rate-limit.go, middleware/turnstile-check.go
Rate-limit and Turnstile middleware replace hardcoded messages with common.TranslateMessage calls using i18n keys; imports adjusted to include i18n.
Multi-locale translation strings
i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml
New auth.* translation entries for all 18 message keys across English, Simplified Chinese, and Traditional Chinese locales, including template variables for system name, verification code, expiry, and reset link.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • QuantumNous/new-api#2842: Introduces i18n infrastructure and common i18n/error utilities that this PR extends for authentication-specific message keys and translations.

Suggested reviewers

  • seefs001

Poem

🐰 Hops with glee through message keys so bright,
Handlers now speak in every tongue right,
From passwords to verifications clear,
i18n translations bring the cheer!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and concisely describes the main change: localizing public authentication messages across email verification, password reset, and related error flows.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Calcium-Ion
Calcium-Ion force-pushed the main branch 2 times, most recently from 51fdfc5 to 2b6f1df Compare August 30, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant