Skip to content

Conversation

@HsnSaboor
Copy link

This PR enables dynamic language switching via the I18N_LANG environment variable.

Key Changes:

  • Core i18n Logic: Added src/i18n.py which supports both async and sync translations.
  • Language Support: Includes i18n/zh.json (original) and a fully translated i18n/en.json (4082 phrases).
  • Backend Refactoring: Systematically replaced Chinese literals in all Python files with ts() translation calls.
  • Frontend Integration: Modified HTML/JS files to use $id_N placeholders, which are replaced at runtime by the FastAPI web router based on the user's language preference.

Setting I18N_LANG=en in .env will now switch the entire application interface and logs to English.

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.
Copilot AI review requested due to automatic review settings January 28, 2026 10:33
Copy link

Copilot AI left a 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.py with async/sync translation functions (t() and ts())
  • 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_N placeholders 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.


def estimate_input_tokens(payload: Dict[str, Any]) -> int:
"""粗略估算 token 数:字符数 / 4 + 图片固定值"""
f"""{ts("id_3631")} token {ts("id_3629f")} / 4 + {ts("id_3630")}"""
Copy link

Copilot AI Jan 28, 2026

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".

Suggested change
f"""{ts("id_3631")} token {ts("id_3629f")} / 4 + {ts("id_3630")}"""
f"""{ts("id_3631")} token {ts("id_3629")} / 4 + {ts("id_3630")}"""

Copilot uses AI. Check for mistakes.
count_str(payload)

# 粗略估算:字符数/4 + 每张图片300 tokens
# {ts("id_3634")}/4 + {ts("id_3635300")} tokens
Copy link

Copilot AI Jan 28, 2026

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.

Suggested change
# {ts("id_3634")}/4 + {ts("id_3635300")} tokens
# {ts("id_3634")}/4 + {ts("id_3635")} 300 tokens

Copilot uses AI. Check for mistakes.
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")}
Copy link

Copilot AI Jan 28, 2026

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".

Suggested change
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")}

Copilot uses AI. Check for mistakes.

try:
# 每3秒发送一次心跳,直到收到响应
# {ts("id_18263")}{ts("id_3231")}
Copy link

Copilot AI Jan 28, 2026

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.

Suggested change
# {ts("id_18263")}{ts("id_3231")}
# {ts("id_1826")}3{ts("id_3231")}

Copilot uses AI. Check for mistakes.
- 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
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