|
50 | 50 | --- OUTPUT FORMAT --- |
51 | 51 | 1. Return ONLY the same list of msgid/msgstr pairs with msgstr filled in. |
52 | 52 | No markdown code fences (```), no explanations, no summaries, no greetings. |
53 | | -2. Every msgid from the input MUST appear exactly once in the output with its |
54 | | - corresponding msgstr filled in. Do not drop, merge, split, or reorder entries. |
55 | | -3. Keep msgid lines COMPLETELY UNCHANGED — never modify source text. |
| 53 | +2. The number of entries in your output MUST EQUAL the number in the input. |
| 54 | + Count them: if you received N entries, you must return exactly N entries. |
| 55 | + Do NOT drop, merge, split, reorder, or add entries under any circumstance. |
| 56 | +3. Keep msgid lines COMPLETELY UNCHANGED — copy them exactly as-is from input. |
56 | 57 |
|
57 | | ---- WHAT TO PRESERVE --- |
| 58 | +--- WHAT TO PRESERVE (keep EXACTLY as in msgid) --- |
58 | 59 | 4. All format specifiers: %s, %d, %f, {{}}, {{{{}}}}, {{name}}, etc. |
59 | 60 | 5. All markdown syntax: **bold**, *italic*, `inline code`, ```code blocks```, |
60 | 61 | [links](urls), , # headings, - lists, 1. ordered lists, |
|
64 | 65 | 8. Proper nouns: person names, contributor names, author names, company names, |
65 | 66 | product names (vLLM, Ascend, CANN, Huawei, etc.). |
66 | 67 |
|
| 68 | +--- CONTENT THAT SHOULD NOT BE TRANSLATED --- |
| 69 | +9. DO NOT translate contributor names, GitHub usernames, or dates. |
| 70 | + These should be copied verbatim from msgid to msgstr. |
| 71 | + Example: "Xiyuan Wang [@wangxiyuan] 2025-01-15" → keep as-is. |
| 72 | +
|
| 73 | +10. DO NOT translate table headers or table separator rows that are purely |
| 74 | + structural. Copy them verbatim. |
| 75 | + Example: "| Name | GitHub ID | Date |" → keep as-is. |
| 76 | + Example: "|:-----------:|:-----:|:-----:|" → keep as-is. |
| 77 | +
|
| 78 | +11. DO NOT translate code identifiers, variable names, CLI flags, or shell |
| 79 | + commands. Copy them verbatim. |
| 80 | + Example: "--data-parallel-size" → keep as-is. |
| 81 | + Example: "vllm serve /path/to/model" → keep as-is. |
| 82 | +
|
| 83 | +12. DO NOT translate URLs, email addresses, or paths. |
| 84 | + Copy them verbatim from msgid to msgstr. |
| 85 | +
|
67 | 86 | --- MkDocs MATERIAL EXTENSIONS --- |
68 | | -These are special MkDocs syntax elements. Keep the KEYWORDS and STRUCTURE |
69 | | -exactly as-is; only translate the human-readable TEXT parts. |
70 | | -
|
71 | | -9. ADMONITIONS: Lines starting with "!!! type" or "!!! type \"title\"". |
72 | | - The type keyword (note, warning, tip, danger, etc.) and the "!!!" marker |
73 | | - MUST stay in English. |
74 | | - Examples: |
75 | | - msgid "!!! note" → msgstr "!!! note" (no translatable text) |
76 | | - msgid "!!! warning" → msgstr "!!! warning" |
77 | | - msgid "!!! note \"Important\"" → msgstr "!!! note \"重要\"" |
78 | | -
|
79 | | -10. COLLAPSIBLE BLOCKS: Lines starting with "??? \"title\"". |
80 | | - Keep "???" and the quote syntax; translate only the title text inside quotes. |
81 | | - Example: |
82 | | - msgid "??? \"Click here to see 'Build from Dockerfile'\"" → msgstr "??? \"点击这里查看'从Dockerfile构建'\"" |
83 | | -
|
84 | | -11. CONTENT TABS: Lines starting with "=== \"label\"". |
85 | | - Keep "===" and the quote syntax; translate only the label text. |
86 | | - Example: |
87 | | - msgid "=== \"Before using pip\"" → msgstr "=== \"使用pip之前\"" |
| 87 | +13. ADMONITIONS (!!! type): Keep "!!!" and type keyword (note, warning, tip) |
| 88 | + in English. Only translate the title text after type. |
| 89 | + Example: msgid "!!! note" → msgstr "!!! note" |
| 90 | + Example: msgid "!!! note \"Important\"" → msgstr "!!! note \"重要\"" |
| 91 | +
|
| 92 | +14. COLLAPSIBLE BLOCKS (???): Keep "???" and quote syntax. Translate only |
| 93 | + the title text inside quotes. |
| 94 | + Example: msgid "??? \"Click here...\"" → msgstr "??? \"点击这里...\"" |
| 95 | +
|
| 96 | +15. CONTENT TABS (===): Keep "===" and quote syntax. Translate only the label. |
| 97 | + Example: msgid "=== \"Before using pip\"" → msgstr "=== \"使用pip之前\"" |
88 | 98 |
|
89 | 99 | --- TRANSLATION QUALITY --- |
90 | | -12. Use natural, fluent Chinese technical documentation style. Avoid word-by-word |
91 | | - literal translation. Restructure long English sentences into natural Chinese |
92 | | - sentence flow. |
93 | | -13. Use standard Chinese technical terminology consistently. |
94 | | -14. For markdown links [text](url): translate the display text in [] but keep the |
95 | | - URL in () exactly as-is. Example: [Quick Start](quick_start.md) → [快速开始](quick_start.md) |
96 | | -15. For headings (# Title): translate the heading text. |
97 | | -16. DO NOT add "#, fuzzy" markers. |
98 | | -17. If a msgid is purely structural (symbols, code, file paths only), copy it |
99 | | - verbatim to msgstr — do not attempt to translate. |
100 | | -18. Never invent or guess content. If genuinely unsure about a term, leave it in |
101 | | - English rather than creating a wrong translation. |
| 100 | +16. Use natural, fluent Chinese technical documentation style. Avoid word-by-word |
| 101 | + literal translation. |
| 102 | +17. Use standard Chinese technical terminology consistently. |
| 103 | +18. For markdown links [text](url): translate the display text in [] but keep |
| 104 | + the URL in () exactly as-is. |
| 105 | + Example: [Quick Start](quick_start.md) → [快速开始](quick_start.md) |
| 106 | +19. For headings (# Title): translate the heading text. |
| 107 | +20. DO NOT add "#, fuzzy" markers. |
| 108 | +21. If a msgid is purely structural (symbols, code, file paths only), copy it |
| 109 | + verbatim to msgstr. |
| 110 | +22. Never invent or guess content. If unsure about a term, leave it in English. |
102 | 111 |
|
103 | 112 | {content}""" |
104 | 113 |
|
@@ -166,13 +175,17 @@ async def translate_file(self, po_path: str) -> bool: |
166 | 175 | return False |
167 | 176 |
|
168 | 177 | # Parse the translated snippet and merge back. |
169 | | - if not self._merge_translations(po, untranslated, translated_snippet): |
| 178 | + merged = self._merge_translations(po, untranslated, translated_snippet) |
| 179 | + if merged == 0: |
170 | 180 | shutil.copy2(backup, po_path) |
171 | 181 | print("FAILED (merge)") |
172 | 182 | return False |
173 | 183 |
|
174 | 184 | po.save(str(path)) |
175 | | - print("OK") |
| 185 | + if merged < len(untranslated): |
| 186 | + print(f"OK ({merged}/{len(untranslated)} merged)") |
| 187 | + else: |
| 188 | + print("OK") |
176 | 189 | return True |
177 | 190 | except Exception as e: |
178 | 191 | print(f"ERROR: {e}") |
@@ -252,26 +265,31 @@ async def do_chunk(idx: int) -> tuple[int, str | None, str | None]: |
252 | 265 | return translated |
253 | 266 |
|
254 | 267 | @staticmethod |
255 | | - def _merge_translations(po, untranslated: list[POEntry], translated_snippet: str) -> bool: |
256 | | - """Parse translated snippet and merge msgstr values back into *po*.""" |
| 268 | + def _merge_translations(po, untranslated: list[POEntry], translated_snippet: str) -> int: |
| 269 | + """Parse translated snippet and merge msgstr values back into *po*. |
| 270 | +
|
| 271 | + Returns the number of entries that were successfully merged. |
| 272 | + If zero entries could be merged, the translation is considered failed. |
| 273 | + """ |
257 | 274 | try: |
258 | 275 | translated_po = pofile(translated_snippet) |
259 | 276 | except Exception: |
260 | | - return False |
| 277 | + return 0 |
261 | 278 |
|
262 | 279 | translated_map: dict[str, str] = {} |
263 | 280 | for entry in translated_po: |
264 | 281 | if entry.msgid and entry.msgstr: |
265 | 282 | translated_map[entry.msgid] = entry.msgstr |
266 | 283 |
|
| 284 | + merged = 0 |
267 | 285 | for entry in untranslated: |
268 | 286 | if entry.msgid in translated_map: |
269 | 287 | entry.msgstr = translated_map[entry.msgid] |
| 288 | + merged += 1 |
270 | 289 | else: |
271 | 290 | print(f"\n Missing translation for: {entry.msgid[:60]}...") |
272 | | - return False |
273 | 291 |
|
274 | | - return True |
| 292 | + return merged |
275 | 293 |
|
276 | 294 | @staticmethod |
277 | 295 | def _clean_response(response: str) -> str: |
|
0 commit comments