Skip to content

Commit 2ae6d2e

Browse files
committed
script fix
1 parent bdab86c commit 2ae6d2e

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
- **Lightweight**: Minimal resource footprint.
7070
- **Flexible**: Runs as a CLI tool, or a full-featured Web Dashboard.
7171
- **Admin-Centric**: Includes features like **VRAM Enforcement** (auto-kill processes exceeding limits) and **Watchlists**.
72-
- **Developer-Friendly**: Built-in benchmarking and stress-testing tools (GEMM, Particle Physics) to validate system stability with cool visuals.
72+
- **Developer-Friendly**: Built-in benchmarking and stress-testing tools (GEMM, Particle Physics) to validate system stability.
7373

7474
---
7575

scripts/translate.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,23 @@
3232
with open(README_PATH, "r", encoding="utf-8") as f:
3333
original_text = f.read()
3434

35-
# --- PRE-PROCESSING: Protect Navigation Bar ---
36-
nav_match = re.search(r'(<div align="center">.*?</div>)', original_text, re.DOTALL)
37-
nav_placeholder = "[NAV_BAR_PROTECTED_BLOCK]"
35+
# --- PRE-PROCESSING: Protect Sensitive Blocks ---
36+
# We replace complex blocks with placeholders so the LLM cannot mangle them.
37+
protected_blocks = []
38+
39+
def protect_match(match):
40+
placeholder = f"[PROTECTED_BLOCK_{len(protected_blocks)}]"
41+
protected_blocks.append(match.group(0))
42+
return placeholder
43+
3844
text_to_translate = original_text
39-
if nav_match:
40-
text_to_translate = text_to_translate.replace(nav_match.group(1), nav_placeholder)
45+
46+
# 1. Protect Navigation Bar (<div align="center">...</div>)
47+
text_to_translate = re.sub(r'(<div align="center">.*?</div>)', protect_match, text_to_translate, flags=re.DOTALL)
48+
# 2. Protect Logo Block (<div style="text-align:center...>)
49+
text_to_translate = re.sub(r'(<div style="text-align:center; margin:18px 0;">.*?</div>)', protect_match, text_to_translate, flags=re.DOTALL)
50+
# 3. Protect Badges (![...](https://img.shields.io/...)) - Prevents URL translation
51+
text_to_translate = re.sub(r'(!\[.*?\]\(https://img\.shields\.io/.*?\))', protect_match, text_to_translate)
4152

4253
# Refined Prompt for CJK and Technical Nuance
4354
prompt = f"""<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|>
@@ -49,7 +60,7 @@
4960
- 'Enforcement' = Policy restriction/application (JA: 制限/強制, ZH: 强制执行).
5061
- 'Headless' = Servers without a display (JA: ヘッドレス, ZH: 无头).
5162
- 'Agnostic' = Independence (JA: 非依存, ZH: 无关性).
52-
4. **Placeholders**: Return any text like '{nav_placeholder}' exactly as is.
63+
4. **Placeholders**: Return any text like '[PROTECTED_BLOCK_X]' exactly as is.
5364
5. **Output**: ONLY the translation. No conversational filler.<|END_OF_TURN_TOKEN|>
5465
<|START_OF_TURN_TOKEN|><|USER_TOKEN|>
5566
{text_to_translate}<|END_OF_TURN_TOKEN|>
@@ -60,21 +71,11 @@
6071

6172
# --- POST-PROCESSING ---
6273

63-
# 1. Restore Navigation Bar
64-
if nav_match:
65-
translated_content = translated_content.replace(nav_placeholder, nav_match.group(1))
66-
67-
# 2. Advanced Badge Restoration (Key-based)
68-
# This handles cases where the LLM translates the URL parameters
69-
badge_keys = ["license", "python", "version", "platform", "cuda"]
70-
for key in badge_keys:
71-
# Find the original badge line for this key
72-
orig_badge = re.search(rf'(!\[.*?\]\(https://img\.shields\.io/badge/{key}.*?\))', original_text, re.I)
73-
if orig_badge:
74-
# Find and replace the translated version in the output
75-
translated_content = re.sub(rf'!\[.*?\]\(https://img\.shields\.io/badge/{key}.*?\)', orig_badge.group(1), translated_content, flags=re.I)
74+
# 1. Restore Protected Blocks
75+
for i, block in enumerate(protected_blocks):
76+
translated_content = translated_content.replace(f"[PROTECTED_BLOCK_{i}]", block)
7677

77-
# 3. Path Correction (Support single and double quotes)
78+
# 2. Path Correction (Support single and double quotes)
7879
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./|locales/))', r'\1../', translated_content)
7980
translated_content = re.sub(r'((?:src|href)=["\'])(?!(?:http|/|#|\.\./|locales/))', r'\1../', translated_content)
8081
translated_content = re.sub(r'(\[.*?\]\()locales/', r'\1', translated_content)

0 commit comments

Comments
 (0)