Skip to content

fix(relay): localize API error messages - #4918

Open
neow021 wants to merge 1 commit into
QuantumNous:mainfrom
neow021:fix/relay-api-error-i18n
Open

fix(relay): localize API error messages#4918
neow021 wants to merge 1 commit into
QuantumNous:mainfrom
neow021:fix/relay-api-error-i18n

Conversation

@neow021

@neow021 neow021 commented May 17, 2026

Copy link
Copy Markdown
Contributor

PR Notice

Description

Several user-facing API and relay errors were still hardcoded as Chinese strings. This moves those messages to the existing i18n locale files and returns localized API errors at the response boundary.

The scope covers token auth checks, model rate limits, playground access token rejection, relay channel retry errors, task saturation messages, and Jimeng upload size validation.

Type of change

  • Bug fix
  • New feature
  • Refactor
  • Documentation

Related Issue

  • N/A

Checklist

  • I manually reviewed and wrote this description.
  • I searched existing issues and PRs and did not find a duplicate.
  • Bug fix note: this PR is not marked as a bug fix.
  • I understand how this change works and its impact.
  • This PR only includes changes related to API/relay error localization.
  • I ran local validation.
  • No secrets or credentials are included.

Proof of Work

  • gofmt -w middleware/auth.go middleware/model-rate-limit.go controller/playground.go controller/relay.go relay/channel/task/jimeng/adaptor.go i18n/keys.go
  • go test ./middleware ./controller ./relay/channel/task/jimeng ./i18n
  • Locale key parity checked for en, zh-CN, and zh-TW
  • YAML parse checked for en, zh-CN, and zh-TW
  • git diff --check

Summary by CodeRabbit

  • Internationalization
    • Authentication error messages now display in user's locale for IP parsing failures, IP allowlist denials, and group access restrictions
    • Channel-related error messages localized for upstream saturation and retry scenarios
    • Added localized messages for playground access token restrictions and task file size limits
    • Translations added for English, Simplified Chinese, and Traditional Chinese

Review Change Stack

- Route token auth, rate-limit, relay retry, playground, and Jimeng upload errors through backend i18n.
- Add matching en, zh-CN, and zh-TW locale messages.
- Keep logs and admin-only text out of scope.
@coderabbitai

coderabbitai Bot commented May 17, 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: 46e84ed8-941a-4efd-a631-cb8aeb8253bb

📥 Commits

Reviewing files that changed from the base of the PR and between f69ceb6 and 4e10c86.

📒 Files selected for processing (9)
  • controller/playground.go
  • controller/relay.go
  • i18n/keys.go
  • i18n/locales/en.yaml
  • i18n/locales/zh-CN.yaml
  • i18n/locales/zh-TW.yaml
  • middleware/auth.go
  • middleware/model-rate-limit.go
  • relay/channel/task/jimeng/adaptor.go

Walkthrough

This PR replaces hardcoded Chinese error messages with localized i18n-driven messaging throughout the application. New translation keys are defined for auth, channel, rate-limit, playground, and task domains, with English and Chinese (Simplified and Traditional) locale strings provided. Middleware, controllers, and adapters are updated to use i18n.T() to retrieve localized messages when denying access or reporting errors.

Changes

Comprehensive i18n localization of error messages

Layer / File(s) Summary
i18n keys and locale translations
i18n/keys.go, i18n/locales/en.yaml, i18n/locales/zh-CN.yaml, i18n/locales/zh-TW.yaml
Introduces new auth-related keys (MsgAuthClientIpParseFailed, MsgAuthIpNotAllowed, MsgAuthGroupAccessDenied, MsgAuthGroupDeprecated, MsgAuthSpecificChannelDenied), channel keys (MsgChannelUpstreamSaturatedUpgrade, MsgChannelGetAvailableRetryFailed, MsgChannelNoAvailableRetry), and domain-specific keys (MsgPlaygroundAccessTokenUnsupported, MsgTaskFileTooLarge). Provides English, Simplified Chinese, and Traditional Chinese translations for each key.
Middleware i18n integration
middleware/auth.go, middleware/model-rate-limit.go
Updates TokenAuth to use i18n messages when denying access due to IP parsing failure, IP allowlist mismatch, group access denial/deprecation, and channel restrictions for non-admin users. Updates rate-limit handlers to localize "success limit reached" and "total limit reached" error messages using i18n.T().
Controller and adapter i18n integration
controller/playground.go, controller/relay.go, relay/channel/task/jimeng/adaptor.go
Replaces hardcoded error strings in playground controller (access token denial), relay controller (channel retry failures, upstream saturation, HTTP 429 responses), and Jimeng adaptor (file-size validation) with localized i18n messages via i18n.T().

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • QuantumNous/new-api#2445: This PR modifies auth client IP parsing and CIDR allowlist denial logic, while the main PR adds i18n localization to those same error paths.
  • QuantumNous/new-api#2842: The retrieved PR establishes the i18n backend infrastructure and helpers (i18n.T, package structure), which this PR extends by defining domain-specific translation keys and applying them across the application.

Poem

🐰 Hardcoded strings once lived alone,
In Chinese whispers, firmly sown.
Now translated to lands afar,
Through i18n's localizing jar!
Error messages sing and dance,
In every tongue, they've got their chance. 🌍

🚥 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(relay): localize API error messages' accurately and clearly summarizes the main change: converting hardcoded error messages to i18n localization across relay and related components.
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