Skip to content

fix(auth): localize WeChat OAuth messages#4907

Open
neow021 wants to merge 2 commits into
QuantumNous:mainfrom
neow021:fix/wechat-custom-oauth-i18n
Open

fix(auth): localize WeChat OAuth messages#4907
neow021 wants to merge 2 commits into
QuantumNous:mainfrom
neow021:fix/wechat-custom-oauth-i18n

Conversation

@neow021

@neow021 neow021 commented May 16, 2026

Copy link
Copy Markdown
Contributor

⚠️ 提交说明 / PR Notice

Important

  • 请提供人工撰写的简洁摘要,避免直接粘贴未经整理的 AI 输出。

📝 变更描述 / Description

Localize user-facing WeChat OAuth login/bind responses and current-user custom OAuth binding responses through the existing backend i18n layer.

This removes hardcoded Chinese responses from ordinary user auth flows, adds matching en, zh-CN, and zh-TW locale keys, and keeps admin custom OAuth provider management endpoints unchanged.

🚀 变更类型 / Type of change

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

🔗 关联任务 / Related Issue

  • N/A, small i18n follow-up for existing auth endpoints.

✅ 提交前检查项 / Checklist

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

📸 运行证明 / Proof of Work

  • gofmt -w controller/custom_oauth.go controller/wechat.go i18n/keys.go
  • go test ./controller ./i18n
  • git diff --check
  • Parsed i18n/locales/en.yaml, zh-CN.yaml, and zh-TW.yaml
  • Confirmed the added locale keys are present in all three locale files

Summary by CodeRabbit

  • New Features
    • Authentication flows (WeChat and custom OAuth) now show localized messages in English, Simplified Chinese, and Traditional Chinese.
    • Success and error notifications for bind/unbind, auth failures, and account-in-use scenarios are translated and presented consistently.
    • Added new localized messages for OAuth unbind success and WeChat-specific errors to improve user-facing clarity.

Review Change Stack

- Route current-user WeChat and custom OAuth responses through backend i18n.
- Add matching en, zh-CN, and zh-TW messages.
- Keep admin custom OAuth management endpoints unchanged.
@coderabbitai

coderabbitai Bot commented May 16, 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: 5054d755-8d66-4940-b792-dd723b8acfd8

📥 Commits

Reviewing files that changed from the base of the PR and between 2f1a01a and a122dff.

📒 Files selected for processing (1)
  • controller/wechat.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • controller/wechat.go

Walkthrough

Adds i18n keys and locale translations, and replaces hardcoded OAuth/WeChat controller messages with i18n-backed API errors and a sentinel-based WeChat error mapping.

Changes

OAuth/WeChat i18n Support

Layer / File(s) Summary
i18n message keys and translations
i18n/keys.go, i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml
New i18n message constants for custom OAuth unbind success (MsgCustomOAuthUnbindSuccess) and WeChat status (MsgWeChatNotEnabled, MsgWeChatAccountUsed) are defined and translated across English and Chinese locales.
Custom OAuth controller i18n integration
controller/custom_oauth.go
GetUserOAuthBindings and UnbindCustomOAuth replace hardcoded authorization errors and the unbind success message with i18n-backed common.ApiErrorI18n responses and i18n.T() lookups.
WeChat controller error handling and i18n
controller/wechat.go
Adds sentinel errors (errWeChatInvalidCode, errWeChatVerificationFailed), centralizes mapping via apiWeChatError, and updates getWeChatIdByCode, WeChatAuth, and WeChatBind to return i18n-backed errors instead of hardcoded JSON payloads.

Sequence Diagram

sequenceDiagram
  participant WeChatAuth as WeChatAuth/WeChatBind
  participant getWeChatIdByCode as getWeChatIdByCode
  participant apiWeChatError as apiWeChatError
  participant ApiErrorI18n as common.ApiErrorI18n
  WeChatAuth->>getWeChatIdByCode: request with code
  alt code empty
    getWeChatIdByCode-->>WeChatAuth: errWeChatInvalidCode
  else verification failed or missing data
    getWeChatIdByCode-->>WeChatAuth: errWeChatVerificationFailed
  end
  WeChatAuth->>apiWeChatError: map sentinel error
  apiWeChatError->>ApiErrorI18n: return localized ApiErrorI18n
  ApiErrorI18n-->>WeChatAuth: localized error response
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • seefs001

Poem

🐰 i18n carrots in my paws tonight,
Controllers sing in every tongue so bright,
WeChat sentinels guard the auth door,
Unbind success now speaks in lore —
Hooray, localized delight! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% 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 title accurately summarizes the main change: localizing WeChat OAuth messages. The PR involves both WeChat and custom OAuth i18n support, with the primary focus on WeChat.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
controller/wechat.go (1)

31-50: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Use common.DecodeJson instead of encoding/json in controller code.

Line 49 uses json.NewDecoder(...).Decode(&res), which violates the project's requirement that all JSON operations in business code must use wrapper functions from common/json.go.

Proposed fix
 import (
-	"encoding/json"
 	"errors"
 	"fmt"
 	"net/http"
 	"net/url"
@@
 	var res wechatLoginResponse
-	err = json.NewDecoder(httpResponse.Body).Decode(&res)
+	err = common.DecodeJson(httpResponse.Body, &res)
 	if err != nil {
 		return "", err
 	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@controller/wechat.go` around lines 31 - 50, The function getWeChatIdByCode
uses encoding/json directly (json.NewDecoder(...).Decode(&res)); replace that
decoding with the project's wrapper: call common.DecodeJson(httpResponse.Body,
&res) and handle its returned error similarly. Update references to
wechatLoginResponse and ensure you still defer httpResponse.Body.Close() and
propagate the error from common.DecodeJson in the same manner the current code
does.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@controller/wechat.go`:
- Around line 31-50: The function getWeChatIdByCode uses encoding/json directly
(json.NewDecoder(...).Decode(&res)); replace that decoding with the project's
wrapper: call common.DecodeJson(httpResponse.Body, &res) and handle its returned
error similarly. Update references to wechatLoginResponse and ensure you still
defer httpResponse.Body.Close() and propagate the error from common.DecodeJson
in the same manner the current code does.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3484d3e1-35bb-469e-94eb-11dd61d26094

📥 Commits

Reviewing files that changed from the base of the PR and between 132d7b9 and 2f1a01a.

📒 Files selected for processing (6)
  • controller/custom_oauth.go
  • controller/wechat.go
  • i18n/keys.go
  • i18n/locales/en.yaml
  • i18n/locales/zh-CN.yaml
  • i18n/locales/zh-TW.yaml

- Decode WeChat login responses through common.DecodeJson.

- Remove direct encoding/json use from the touched controller.
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.

2 participants