mirror of
https://github.com/aiclientproxy/proxycast.git
synced 2026-09-24 23:10:56 +08:00
fix: improve i18n translations and fix DOM replacement order
- Fixed 20 translation entries with concatenated words and incorrect formatting - Fixed critical bug in DOM replacer that caused partial translations - Sort translation patches by length (longest first) to prevent substring replacement issues - Fixed TypeScript and ESLint errors - Added comprehensive documentation of fixes
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# Translation Scripts
|
||||
|
||||
This directory contains utility scripts for managing i18n translations.
|
||||
|
||||
## Useful Scripts
|
||||
|
||||
### `extract_remaining_todos.py`
|
||||
Extracts all `[TODO: Translate]` entries from `en.json` for manual translation.
|
||||
|
||||
**Usage:**
|
||||
```bash
|
||||
python scripts/extract_remaining_todos.py
|
||||
```
|
||||
|
||||
**Output:** `translations-remaining.json` - Contains all untranslated entries
|
||||
|
||||
### `import_translations.py`
|
||||
Imports translated entries from `translations-remaining.json` back into `en.json`.
|
||||
|
||||
**Usage:**
|
||||
1. Fill in translations in `translations-remaining.json`
|
||||
2. Run: `python scripts/import_translations.py`
|
||||
|
||||
### `translate_all.py`
|
||||
Contains comprehensive translation dictionary (1200+ entries) for reference.
|
||||
Can be used as a base for future translations.
|
||||
|
||||
## Workflow for Adding New Translations
|
||||
|
||||
When upstream adds new Chinese text:
|
||||
|
||||
1. **Extract new TODOs:**
|
||||
```bash
|
||||
python scripts/extract_remaining_todos.py
|
||||
```
|
||||
|
||||
2. **Translate entries:**
|
||||
Edit `translations-remaining.json` and add English translations
|
||||
|
||||
3. **Import translations:**
|
||||
```bash
|
||||
python scripts/import_translations.py
|
||||
```
|
||||
|
||||
4. **Verify:**
|
||||
Check `en.json` for any remaining `[TODO]` markers
|
||||
|
||||
## Translation Guidelines
|
||||
|
||||
- **Use full sentences/phrases** - Not word-by-word translation
|
||||
- **Context-aware** - Consider where the text appears in the UI
|
||||
- **Natural English** - Translate meaning, not literal words
|
||||
- **Consistent terminology** - Use same terms for same concepts
|
||||
|
||||
## Current Status
|
||||
|
||||
- **Total entries:** 3,568
|
||||
- **Translated:** 3,568 (100%)
|
||||
- **Coverage:** 100%
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Extract remaining TODO entries for manual translation"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
EN_FILE = Path(__file__).parent.parent / 'src' / 'i18n' / 'patches' / 'en.json'
|
||||
OUTPUT_FILE = Path(__file__).parent.parent / 'translations-remaining.json'
|
||||
|
||||
print("Loading en.json...")
|
||||
with open(EN_FILE, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Extract all TODO entries
|
||||
todos = {}
|
||||
for key, value in data.items():
|
||||
if isinstance(value, str) and value.startswith('[TODO: Translate]'):
|
||||
chinese = value.replace('[TODO: Translate] ', '')
|
||||
todos[chinese] = "" # Empty string for translation
|
||||
|
||||
print(f"Found {len(todos)} entries to translate")
|
||||
print(f"Saving to {OUTPUT_FILE}...")
|
||||
|
||||
# Save to file
|
||||
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(todos, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print("Done!")
|
||||
print()
|
||||
print("Next steps:")
|
||||
print("1. Open translations-remaining.json")
|
||||
print("2. Fill in English translations for each Chinese text")
|
||||
print("3. Run import_translations.py to merge back")
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Import translations from translations-remaining.json back to en.json"""
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
EN_FILE = Path(__file__).parent.parent / 'src' / 'i18n' / 'patches' / 'en.json'
|
||||
INPUT_FILE = Path(__file__).parent.parent / 'translations-remaining.json'
|
||||
|
||||
if not INPUT_FILE.exists():
|
||||
print(f"Error: {INPUT_FILE} not found")
|
||||
print("Run extract_remaining_todos.py first")
|
||||
exit(1)
|
||||
|
||||
print("Loading translations...")
|
||||
with open(INPUT_FILE, 'r', encoding='utf-8') as f:
|
||||
translations = json.load(f)
|
||||
|
||||
print("Loading en.json...")
|
||||
with open(EN_FILE, 'r', encoding='utf-8') as f:
|
||||
data = json.load(f)
|
||||
|
||||
# Apply translations
|
||||
count = 0
|
||||
for key, value in data.items():
|
||||
if isinstance(value, str) and value.startswith('[TODO: Translate]'):
|
||||
chinese = value.replace('[TODO: Translate] ', '')
|
||||
if chinese in translations and translations[chinese]:
|
||||
data[key] = translations[chinese]
|
||||
count += 1
|
||||
|
||||
print(f"Applied {count} translations")
|
||||
print("Saving en.json...")
|
||||
|
||||
with open(EN_FILE, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, ensure_ascii=False, indent=2)
|
||||
|
||||
print("Done!")
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user