feat: Add i18n for apiserver.#68
Conversation
Reviewer's GuideThis PR implements full internationalization support by introducing a backend i18n package with error/response helpers, initializing the translator at startup, refactoring all API handlers to use the new i18n methods, extending the frontend with language headers and centralized error handling, adding WebSocket language propagation, including English and Chinese translation files, updating dependencies, and shipping comprehensive documentation. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @iFurySt - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 5 issues found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| const response = await api.get('/mcp-servers', { params }); | ||
| return response.data; | ||
| // 处理数据,兼容直接返回和嵌套在 data 中的情况 | ||
| return response.data.data || response.data; |
There was a problem hiding this comment.
suggestion (bug_risk): The fallback to response.data may mask cases where data is intentionally null or falsy.
Switch to response.data.data ?? response.data so that only null or undefined values fall back, preserving valid falsy returns.
| return response.data.data || response.data; | |
| return response.data.data ?? response.data; |
| duration: 3000, | ||
| }); | ||
| } | ||
| handleApiError(error, 'errors.fetch_mcp_servers'); |
There was a problem hiding this comment.
suggestion: handleApiError is used for most endpoints, but not for getUsers, getUser, and getUserWithTenants.
Switch error handling in getUsers, getUser, and getUserWithTenants to use handleApiError instead of toast.error to centralize handling and keep feedback consistent.
| const response = await api.get('/auth/user'); | ||
| return response.data.tenants || []; | ||
| // 处理数据,兼容直接返回和嵌套在 data 中的情况 | ||
| const data = response.data.data || response.data; |
There was a problem hiding this comment.
suggestion: The same fallback logic as above may cause issues with falsy values.
Switch to response.data.data ?? response.data to avoid masking valid falsy values.
| const token = window.localStorage.getItem('token'); | ||
| this.ws = new WebSocket(`${import.meta.env.VITE_WS_BASE_URL}/chat?sessionId=${this.sessionId}&token=${token}`); | ||
| // Include language parameter in WebSocket URL | ||
| const lang = localStorage.getItem('i18nextLng') || 'zh'; |
There was a problem hiding this comment.
suggestion: Default language fallback is hardcoded to 'zh', which may not match the application's default.
Use a shared constant or config value for the default language instead of hardcoding 'zh' to ensure consistent fallbacks across the app.
| func GetTranslator() *I18n { | ||
| if translator == nil { | ||
| // Initialize with default path if not already initialized | ||
| _ = InitTranslator("configs/i18n") |
There was a problem hiding this comment.
issue (bug_risk): Implicit initialization of the translator may hide errors.
Log or propagate the InitTranslator error so failures don’t go unnoticed.
Summary by Sourcery
Add comprehensive internationalization (i18n) support across the API server and web client, replacing hard-coded messages with translated responses and enabling language selection.
New Features:
Enhancements:
Build:
Documentation: