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
Copy link
Copy Markdown

@neow021 neow021 commented May 16, 2026

⚠️ 提交说明 / 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
    • WeChat authentication and OAuth account management features now display all error messages and success confirmations in English, Simplified Chinese, and Traditional Chinese. This includes notifications for authentication failures, account binding, unbinding operations, and related account management workflows, providing consistent language support throughout authentication processes.

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
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 16, 2026

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ 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
 _____________________________________________________________________________________________________________
< Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. >
 -------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ

Walkthrough

This PR adds internationalization support to custom OAuth and WeChat authentication flows by introducing new i18n message keys, providing translations across multiple locales, and updating controller error and success responses to use locale-aware messaging instead of hardcoded strings.

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() message lookups.
WeChat controller error handling and i18n
controller/wechat.go
Package-level sentinel errors (errWeChatInvalidCode, errWeChatVerificationFailed) standardize verification failures in getWeChatIdByCode. A new apiWeChatError function maps these sentinels to i18n API responses. WeChatAuth and WeChatBind route errors through this mapper and replace hardcoded JSON payloads with i18n-based error messages.

Sequence Diagram

sequenceDiagram
    participant WeChatAuth as WeChatAuth/WeChatBind
    participant getWeChatIdByCode as getWeChatIdByCode
    participant apiWeChatError as apiWeChatError
    participant ApiErrorI18n as ApiErrorI18n
    WeChatAuth->>getWeChatIdByCode: call with code
    alt Invalid Code
        getWeChatIdByCode-->>WeChatAuth: errWeChatInvalidCode
    else Verification Failed
        getWeChatIdByCode-->>WeChatAuth: errWeChatVerificationFailed
    end
    WeChatAuth->>apiWeChatError: map sentinel error
    apiWeChatError->>ApiErrorI18n: translate to i18n response
    ApiErrorI18n-->>WeChatAuth: localized API error
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • QuantumNous/new-api#2842: Introduces the underlying i18n helper APIs (ApiErrorI18n, TranslateMessage) that this PR depends on for localized error/success responses.
  • QuantumNous/new-api#2913: Establishes Traditional Chinese (zh-TW) locale support that this PR extends with new WeChat and custom OAuth message entries.

Suggested reviewers

  • Calcium-Ion
  • seefs001

Poem

🐰 With i18n keys now in place,
OAuth flows speak many tongues with grace,
WeChat sentinel errors stand so tall,
Localized messages for one and all! 🌍✨

🚥 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 'fix(auth): localize WeChat OAuth messages' directly and accurately describes the main change: adding i18n support to WeChat OAuth and custom OAuth authentication responses.
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.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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