-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat: implement comprehensive i18n support with English translation #303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
feat: implement comprehensive i18n support with English translation #303
Conversation
This commit enables dynamic language switching via I18N_LANG environment variable. It includes a complete extraction of Chinese text from the codebase and provides a fully translated en.json file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR implements comprehensive internationalization (i18n) support by introducing a translation system that enables switching between Chinese (default) and English via the I18N_LANG environment variable.
Changes:
- Added
src/i18n.pywith async/sync translation functions (t()andts()) - Replaced Chinese string literals throughout Python codebase with
ts("id_N")translation keys - Created translation files (
i18n/zh.json,i18n/en.json) containing 4082+ phrase mappings - Modified HTML/JS files to use
$id_Nplaceholders for runtime language replacement
Reviewed changes
Copilot reviewed 36 out of 44 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/i18n.py | Core i18n module with translation loading and key lookup |
| src/token_estimator.py | Replaced docstrings and comments with translation calls |
| src/task_manager.py | Replaced docstrings and comments with translation calls |
| src/storage_adapter.py | Replaced docstrings and comments with translation calls |
| src/router/hi_check.py | Replaced docstrings and comments with translation calls |
| src/router/geminicli/openai.py | Replaced docstrings and comments with translation calls |
| src/router/geminicli/model_list.py | Replaced docstrings and comments with translation calls |
| src/router/geminicli/anthropic.py | Replaced docstrings and comments with translation calls |
| src/router/antigravity/openai.py | Replaced docstrings and comments with translation calls |
| src/router/antigravity/model_list.py | Replaced docstrings and comments with translation calls |
| src/router/antigravity/anthropic.py | Replaced docstrings and comments with translation calls |
| src/router/base_router.py | Replaced docstrings and comments with translation calls |
| src/models.py | Replaced comments with translation calls |
| src/httpx_client.py | Replaced docstrings and comments with translation calls |
| src/google_oauth_api.py | Replaced docstrings and comments with translation calls |
| src/credential_manager.py | Replaced docstrings and comments with translation calls |
| src/converter/utils.py | Replaced docstrings and comments with translation calls |
| src/converter/thoughtSignature_fix.py | Replaced docstrings and comments with translation calls |
| src/converter/gemini_fix.py | Replaced docstrings and comments with translation calls |
| src/converter/fake_stream.py | Replaced docstrings and comments with translation calls |
| src/api/utils.py | Replaced docstrings and comments with translation calls |
| scripts/apply_front_i18n.py | New script for HTML/JS placeholder replacement |
| log.py | Replaced docstrings and comments with translation calls |
| config.py | Replaced comments with translation calls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/token_estimator.py
Outdated
|
|
||
| def estimate_input_tokens(payload: Dict[str, Any]) -> int: | ||
| """粗略估算 token 数:字符数 / 4 + 图片固定值""" | ||
| f"""{ts("id_3631")} token {ts("id_3629f")} / 4 + {ts("id_3630")}""" |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translation key "id_3629f" contains an unusual "f" suffix. This appears to be a typo and should likely be "id_3629".
| f"""{ts("id_3631")} token {ts("id_3629f")} / 4 + {ts("id_3630")}""" | |
| f"""{ts("id_3631")} token {ts("id_3629")} / 4 + {ts("id_3630")}""" |
src/token_estimator.py
Outdated
| count_str(payload) | ||
|
|
||
| # 粗略估算:字符数/4 + 每张图片300 tokens | ||
| # {ts("id_3634")}/4 + {ts("id_3635300")} tokens |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translation key "id_3635300" appears to combine the ID with the number "300". This should likely be two separate elements: "id_3635" for the text and "300" as a literal number.
| # {ts("id_3634")}/4 + {ts("id_3635300")} tokens | |
| # {ts("id_3634")}/4 + {ts("id_3635")} 300 tokens |
src/router/hi_check.py
Outdated
| request_data: 请求数据 | ||
| format: 请求格式("openai"、"gemini" 或 "anthropic") | ||
| request_data: {ts("id_2410")} | ||
| format: {ts(f"id_3369")}"openai"{ts("id_189")}"geminif" {ts("id_413")} "anthropic"{ts("id_292")} |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The string "geminif" contains an unusual "f" suffix that appears to be a typo. This should likely be "gemini".
| format: {ts(f"id_3369")}"openai"{ts("id_189")}"geminif" {ts("id_413")} "anthropic"{ts("id_292")} | |
| format: {ts(f"id_3369")}"openai"{ts("id_189")}"gemini" {ts("id_413")} "anthropic"{ts("id_292")} |
src/router/geminicli/openai.py
Outdated
|
|
||
| try: | ||
| # 每3秒发送一次心跳,直到收到响应 | ||
| # {ts("id_18263")}{ts("id_3231")} |
Copilot
AI
Jan 28, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translation key "id_18263" appears malformed - it likely should be "id_1826" followed by "3" as part of the translation text (representing "3 seconds"), not part of the ID itself.
| # {ts("id_18263")}{ts("id_3231")} | |
| # {ts("id_1826")}3{ts("id_3231")} |
- Fixed 'id_3629f' typo to 'id_3629' in token_estimator.py - Separated 'id_3635300' into 'id_3635' and literal '300' in token_estimator.py - Fixed 'geminif' typo to 'gemini' in hi_check.py - Fixed 'id_18263' malformed key to 'id_1826' and literal '3' in geminicli/openai.py - Fixed circular dependency between config.py and src/i18n.py
…dencies in i18n implementation
This PR enables dynamic language switching via the
I18N_LANGenvironment variable.Key Changes:
src/i18n.pywhich supports both async and sync translations.i18n/zh.json(original) and a fully translatedi18n/en.json(4082 phrases).ts()translation calls.$id_Nplaceholders, which are replaced at runtime by the FastAPI web router based on the user's language preference.Setting
I18N_LANG=enin.envwill now switch the entire application interface and logs to English.