Skip to content

Commit 04a317b

Browse files
committed
prompt engineering fix
1 parent 23860e5 commit 04a317b

File tree

3 files changed

+59
-39
lines changed

3 files changed

+59
-39
lines changed

.github/workflows/translate.yml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,38 @@ jobs:
4848
- name: Run Translation Script
4949
run: python scripts/translate.py --lang ${{ matrix.lang }}
5050

51-
- name: Upload Translation Artifact
52-
uses: actions/upload-artifact@v4
53-
with:
54-
name: readme-${{ matrix.lang }}
55-
path: locales/README.${{ matrix.lang }}.md
51+
- name: Commit and Push
52+
run: |
53+
git config --global user.name "github-actions[bot]"
54+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
55+
git add locales/README.${{ matrix.lang }}.md
56+
git commit -m "docs: update ${{ matrix.lang }} translation" || echo "No changes to commit"
57+
git pull --rebase
58+
git push
5659
57-
commit-translations:
58-
needs: translate
59-
runs-on: ubuntu-latest
60-
steps:
61-
- name: Checkout Code
62-
uses: actions/checkout@v4
60+
# - name: Upload Translation Artifact
61+
# uses: actions/upload-artifact@v4
62+
# with:
63+
# name: readme-${{ matrix.lang }}
64+
# path: locales/README.${{ matrix.lang }}.md
6365

64-
- name: Download All Translations
65-
uses: actions/download-artifact@v4
66-
with:
67-
pattern: readme-*
68-
path: locales
69-
merge-multiple: true
66+
# commit-translations:
67+
# needs: translate
68+
# runs-on: ubuntu-latest
69+
# steps:
70+
# - name: Checkout Code
71+
# uses: actions/checkout@v4
7072

71-
- name: Commit and Push Changes
72-
uses: stefanzweifel/git-auto-commit-action@v5
73-
with:
74-
commit_message: "docs: update multilingual translations"
75-
file_pattern: 'locales/*.md'
76-
push_options: '--force-with-lease'
73+
# - name: Download All Translations
74+
# uses: actions/download-artifact@v4
75+
# with:
76+
# pattern: readme-*
77+
# path: locales
78+
# merge-multiple: true
79+
80+
# - name: Commit and Push Changes
81+
# uses: stefanzweifel/git-auto-commit-action@v5
82+
# with:
83+
# commit_message: "docs: update multilingual translations"
84+
# file_pattern: 'locales/*.md'
85+
# push_options: '--force-with-lease'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
### Why use this?
6868

6969
- **Lightweight**: Minimal resource footprint.
70-
- **Flexible**: Runs as a CLI tool, a background service, or a full-featured Web Dashboard.
70+
- **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**.
7272
- **Developer-Friendly**: Built-in benchmarking and stress-testing tools (GEMM, Particle Physics) to validate system stability.
7373

scripts/translate.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,24 +75,35 @@
7575
translated_content = "\n".join(lines).strip()
7676

7777
# 2. FIX PATHS: Handle relative paths for files in /locales/
78-
# First, remove "locales/" if the LLM hallucinated it into the path
78+
# We need to ensure that links to the root go up one level (../)
79+
# but links to other files in the same /locales/ folder stay relative.
80+
81+
# Step 1: Prepend ../ to relative paths (ignoring external links, absolute paths, anchors, or locales/)
82+
# This targets Markdown links/images text and HTML src="path"/href="path"
83+
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./|locales/))', r'\1../', translated_content)
84+
translated_content = re.sub(r'((?:src|href)=")(?!(?:http|/|#|\.\./|locales/))', r'\1../', translated_content)
85+
86+
# Step 2: Handle links that point to the locales directory.
87+
# Since the translated file is ALREADY in /locales/, we strip the 'locales/' prefix
88+
# so they point to the sibling files in the same directory.
7989
translated_content = re.sub(r'(\[.*?\]\()locales/', r'\1', translated_content)
8090
translated_content = re.sub(r'((?:src|href)=")locales/', r'\1', translated_content)
8191

82-
# Then, prepend ../ to relative paths (ignoring external links, absolute paths, or anchors)
83-
# This targets Markdown links/images text and HTML src="path"/href="path"
84-
translated_content = re.sub(r'(\[.*?\]\()(?!(?:http|/|#|\.\./))', r'\1../', translated_content)
85-
translated_content = re.sub(r'((?:src|href)=")(?!(?:http|/|#|\.\./))', r'\1../', translated_content)
86-
87-
# List of badges that should NEVER be translated
88-
protected_badges = ["License", "Python", "Version", "Platform", "cuda 12.x"]
89-
90-
for badge in protected_badges:
91-
# This regex finds translated versions of badges by looking for the
92-
# specific Shields.io URL and replacing label back to the original.
93-
# Pattern matches: ![Anything](URL containing shields.io and the badge key)
94-
pattern = rf'!\[.*?\]\(https://img\.shields\.io/badge/{badge.lower()}.*?\)'
95-
original_badge_line = f"![{badge}](...)" # Map your original lines here
92+
# 3. RESTORE BADGES: Ensure badges match the original English README exactly.
93+
# This fixes cases where the LLM translates the Alt text (e.g., ![License] -> ![Lizenz])
94+
# or slightly alters the URL.
95+
96+
# Extract all shields.io badges from the original source text
97+
original_badges = re.findall(r'(!\[.*?\]\(https://img\.shields\.io/.*?\))', text_to_translate)
98+
99+
for badge in original_badges:
100+
# Extract the URL from the original badge to use as a key
101+
match = re.search(r'\((https://img\.shields\.io/.*?)\)', badge)
102+
if match:
103+
url = match.group(1)
104+
# Replace any markdown image in the translated text that has this URL
105+
# with the exact original badge string.
106+
translated_content = re.sub(rf'!\[.*?\]\({re.escape(url)}\)', lambda m: badge, translated_content)
96107

97108
with open(OUTPUT_PATH, "w", encoding="utf-8") as f:
98109
f.write(translated_content)

0 commit comments

Comments
 (0)