i18n: Translate all Chinese to English across the codebase

Translate Chinese comments, log/error messages, validator labels and
Swagger annotations to English throughout the source code, generated
Swagger docs, config files and CI workflows.

Make the English README primary: README.md now holds the English docs
and README_EN.md holds the Chinese version, with cross-language links
updated accordingly.

Note: the generated docs/ swagger files were translated in place; run
`go generate ./...` (swag init) to regenerate them from the now-English
annotations when a Go toolchain is available.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-27 12:17:04 +02:00
co-authored by Claude Opus 4.8
parent c5687e1506
commit 16e97c8efa
103 changed files with 3088 additions and 3086 deletions
+62 -62
View File
@@ -33,7 +33,7 @@ func TestSecurityWorkflow(t *testing.T) {
limiter := NewLoginLimiter(policy)
ip := "192.168.1.100"
// 测试正常失败记录
// test normal failure recording
for i := 0; i < 3; i++ {
limiter.RecordFailedAttempt(ip)
}
@@ -45,14 +45,14 @@ func TestSecurityWorkflow(t *testing.T) {
if !capRequired {
t.Error("Captcha should be required")
}
// 测试触发封禁
// test triggering a ban
for i := 0; i < 3; i++ {
limiter.RecordFailedAttempt(ip)
isBanned, capRequired = limiter.CheckSecurityStatus(ip)
fmt.Printf("IP: %s, Banned: %v, Captcha Required: %v\n", ip, isBanned, capRequired)
}
// 测试封禁状态
// test ban status
if isBanned, _ = limiter.CheckSecurityStatus(ip); !isBanned {
t.Error("IP should be banned")
}
@@ -64,36 +64,36 @@ func TestCaptchaFlow(t *testing.T) {
limiter.RegisterProvider(&MockCaptchaProvider{})
ip := "10.0.0.1"
// 触发验证码要求
// trigger captcha requirement
limiter.RecordFailedAttempt(ip)
limiter.RecordFailedAttempt(ip)
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
// 生成验证码
// generate captcha
err, capc := limiter.RequireCaptcha()
if err != nil {
t.Fatalf("生成验证码失败: %v", err)
t.Fatalf("failed to generate captcha: %v", err)
}
fmt.Printf("验证码内容: %#v\n", capc)
fmt.Printf("captcha content: %#v\n", capc)
// 验证成功
// verify successfully
if !limiter.VerifyCaptcha(capc.Id, capc.Answer) {
t.Error("验证码应该验证成功")
t.Error("captcha should verify successfully")
}
// 验证已删除
// verify it has been deleted
if limiter.VerifyCaptcha(capc.Id, capc.Answer) {
t.Error("验证码应该已删除")
t.Error("captcha should have been deleted")
}
limiter.RemoveAttempts(ip)
// 验证后状态
// state after verification
if banned, need := limiter.CheckSecurityStatus(ip); banned || need {
t.Error("验证成功后应该重置状态")
t.Error("state should be reset after successful verification")
}
}
@@ -103,26 +103,26 @@ func TestCaptchaMustFlow(t *testing.T) {
limiter.RegisterProvider(&MockCaptchaProvider{})
ip := "10.0.0.1"
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
// 生成验证码
// generate captcha
err, capc := limiter.RequireCaptcha()
if err != nil {
t.Fatalf("生成验证码失败: %v", err)
t.Fatalf("failed to generate captcha: %v", err)
}
fmt.Printf("验证码内容: %#v\n", capc)
fmt.Printf("captcha content: %#v\n", capc)
// 验证成功
// verify successfully
if !limiter.VerifyCaptcha(capc.Id, capc.Answer) {
t.Error("验证码应该验证成功")
t.Error("captcha should verify successfully")
}
// 验证后状态
// state after verification
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
}
func TestAttemptTimeout(t *testing.T) {
@@ -131,28 +131,28 @@ func TestAttemptTimeout(t *testing.T) {
limiter.RegisterProvider(&MockCaptchaProvider{})
ip := "10.0.0.1"
// 触发验证码要求
// trigger captcha requirement
limiter.RecordFailedAttempt(ip)
limiter.RecordFailedAttempt(ip)
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
// 生成验证码
// generate captcha
err, _ := limiter.RequireCaptcha()
if err != nil {
t.Fatalf("生成验证码失败: %v", err)
t.Fatalf("failed to generate captcha: %v", err)
}
// 等待超过 AttemptsWindow
// wait beyond AttemptsWindow
time.Sleep(2 * time.Second)
// 触发验证码要求
// trigger captcha requirement
limiter.RecordFailedAttempt(ip)
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); need {
t.Error("不应该需要验证码")
t.Error("captcha should not be required")
}
}
@@ -162,27 +162,27 @@ func TestCaptchaTimeout(t *testing.T) {
limiter.RegisterProvider(&MockCaptchaProvider{})
ip := "10.0.0.1"
// 触发验证码要求
// trigger captcha requirement
limiter.RecordFailedAttempt(ip)
limiter.RecordFailedAttempt(ip)
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
// 生成验证码
// generate captcha
err, capc := limiter.RequireCaptcha()
if err != nil {
t.Fatalf("生成验证码失败: %v", err)
t.Fatalf("failed to generate captcha: %v", err)
}
// 等待超过 CaptchaValidPeriod
// wait beyond CaptchaValidPeriod
time.Sleep(3 * time.Second)
// 验证成功
// verify successfully
if limiter.VerifyCaptcha(capc.Id, capc.Answer) {
t.Error("验证码应该已过期")
t.Error("captcha should have expired")
}
}
@@ -191,12 +191,12 @@ func TestBanFlow(t *testing.T) {
policy := SecurityPolicy{BanThreshold: 5}
limiter := NewLoginLimiter(policy)
ip := "10.0.0.1"
// 触发ban
// trigger ban
for i := 0; i < 5; i++ {
limiter.RecordFailedAttempt(ip)
}
// 检查状态
// check status
if banned, _ := limiter.CheckSecurityStatus(ip); !banned {
t.Error("should be banned")
}
@@ -205,12 +205,12 @@ func TestBanDisableFlow(t *testing.T) {
policy := SecurityPolicy{BanThreshold: 0}
limiter := NewLoginLimiter(policy)
ip := "10.0.0.1"
// 触发ban
// trigger ban
for i := 0; i < 5; i++ {
limiter.RecordFailedAttempt(ip)
}
// 检查状态
// check status
if banned, _ := limiter.CheckSecurityStatus(ip); banned {
t.Error("should not be banned")
}
@@ -219,15 +219,15 @@ func TestBanTimeout(t *testing.T) {
policy := SecurityPolicy{BanThreshold: 5, BanDuration: 1 * time.Second}
limiter := NewLoginLimiter(policy)
ip := "10.0.0.1"
// 触发ban
// 触发ban
// trigger ban
// trigger ban
for i := 0; i < 5; i++ {
limiter.RecordFailedAttempt(ip)
}
time.Sleep(2 * time.Second)
// 检查状态
// check status
if banned, _ := limiter.CheckSecurityStatus(ip); banned {
t.Error("should not be banned")
}
@@ -237,12 +237,12 @@ func TestLimiterDisabled(t *testing.T) {
policy := SecurityPolicy{BanThreshold: 0, CaptchaThreshold: -1}
limiter := NewLoginLimiter(policy)
ip := "10.0.0.1"
// 触发ban
// trigger ban
for i := 0; i < 5; i++ {
limiter.RecordFailedAttempt(ip)
}
// 检查状态
// check status
if banned, capNeed := limiter.CheckSecurityStatus(ip); banned || capNeed {
fmt.Printf("IP: %s, Banned: %v, Captcha Required: %v\n", ip, banned, capNeed)
t.Error("should not be banned or need captcha")
@@ -254,37 +254,37 @@ func TestB64CaptchaFlow(t *testing.T) {
limiter.RegisterProvider(B64StringCaptchaProvider{})
ip := "10.0.0.1"
// 触发验证码要求
// trigger captcha requirement
limiter.RecordFailedAttempt(ip)
limiter.RecordFailedAttempt(ip)
limiter.RecordFailedAttempt(ip)
// 检查状态
// check status
if _, need := limiter.CheckSecurityStatus(ip); !need {
t.Error("应该需要验证码")
t.Error("captcha should be required")
}
// 生成验证码
// generate captcha
err, capc := limiter.RequireCaptcha()
if err != nil {
t.Fatalf("生成验证码失败: %v", err)
t.Fatalf("failed to generate captcha: %v", err)
}
fmt.Printf("验证码内容: %#v\n", capc)
fmt.Printf("captcha content: %#v\n", capc)
//draw
err, b64 := limiter.DrawCaptcha(capc.Content)
if err != nil {
t.Fatalf("绘制验证码失败: %v", err)
t.Fatalf("failed to draw captcha: %v", err)
}
fmt.Printf("验证码内容: %#v\n", b64)
fmt.Printf("captcha content: %#v\n", b64)
// 验证成功
// verify successfully
if !limiter.VerifyCaptcha(capc.Id, capc.Answer) {
t.Error("验证码应该验证成功")
t.Error("captcha should verify successfully")
}
limiter.RemoveAttempts(ip)
// 验证后状态
// state after verification
if banned, need := limiter.CheckSecurityStatus(ip); banned || need {
t.Error("验证成功后应该重置状态")
t.Error("state should be reset after successful verification")
}
}