Skip to content

Commit 244ce39

Browse files
authored
Improve translation prompt guidance (#1647)
1 parent 184757b commit 244ce39

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

docs/scripts/translate_docs.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,27 @@ def built_instructions(target_language: str, lang_code: str) -> str:
136136
- Fenced code blocks delimited by ``` or ~~~, including all comments inside them.
137137
- Link URLs inside `[label](URL)` – translate the label, never the URL.
138138
139+
#########################
140+
## HARD CONSTRAINTS ##
141+
#########################
142+
- Never insert spaces immediately inside emphasis markers. Use `**bold**`, not `** bold **`.
143+
- Preserve the number of emphasis markers from the source: if the source uses `**` or `__`, keep the same pair count.
144+
- Ensure one space after heading markers: `##Heading` -> `## Heading`.
145+
- Ensure one space after list markers: `-Item` -> `- Item`, `*Item` -> `* Item` (does not apply to `**`).
146+
- Trim spaces inside link/image labels: `[ Label ](url)` -> `[Label](url)`.
147+
148+
###########################
149+
## GOOD / BAD EXAMPLES ##
150+
###########################
151+
- Good: This is **bold** text.
152+
- Bad: This is ** bold ** text.
153+
- Good: ## Heading
154+
- Bad: ##Heading
155+
- Good: - Item
156+
- Bad: -Item
157+
- Good: [Label](https://example.com)
158+
- Bad: [ Label ](https://example.com)
159+
139160
#########################
140161
## LANGUAGE‑SPECIFIC ##
141162
#########################
@@ -159,6 +180,7 @@ def built_instructions(target_language: str, lang_code: str) -> str:
159180
## EXTRA GUIDELINES ##
160181
#########################
161182
{specific_instructions}
183+
- When translating Markdown tables, preserve the exact table structure, including all delimiters (|), header separators (---), and row/column counts. Only translate the cell contents. Do not add, remove, or reorder columns or rows.
162184
163185
#########################
164186
## IF UNSURE ##
@@ -173,7 +195,11 @@ def built_instructions(target_language: str, lang_code: str) -> str:
173195
174196
1. Read the input markdown text given by the user.
175197
2. Translate the markdown file into {target_language}, carefully following the requirements above.
176-
3. Self-review your translation to ensure high quality, focusing on naturalness, accuracy, and consistency while avoiding unnecessary changes or spacing.
198+
3. Perform a self-review to check for the following common issues:
199+
- Naturalness, accuracy, and consistency throughout the text.
200+
- Spacing inside markdown syntax such as `*` or `_`; `**bold**` is correct whereas `** bold **` is not.
201+
- Unwanted spaces inside link or image labels, such as `[ Label ](url)`.
202+
- Headings or list markers missing a space after their marker.
177203
4. If improvements are necessary, refine the content without changing the original meaning.
178204
5. Continue improving the translation until you are fully satisfied with the result.
179205
6. Once the final output is ready, return **only** the translated markdown text. No extra commentary.
@@ -208,7 +234,7 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
208234
code_block_chunks.append(line)
209235
if in_code_block is True:
210236
code_blocks.append("\n".join(code_block_chunks))
211-
current_chunk.append(f"CODE_BLOCK_{(len(code_blocks) - 1):02}")
237+
current_chunk.append(f"CODE_BLOCK_{(len(code_blocks) - 1):03}")
212238
code_block_chunks.clear()
213239
in_code_block = not in_code_block
214240
continue
@@ -250,7 +276,7 @@ def translate_file(file_path: str, target_path: str, lang_code: str) -> None:
250276

251277
translated_text = "\n".join(translated_content)
252278
for idx, code_block in enumerate(code_blocks):
253-
translated_text = translated_text.replace(f"CODE_BLOCK_{idx:02}", code_block)
279+
translated_text = translated_text.replace(f"CODE_BLOCK_{idx:03}", code_block)
254280

255281
# FIXME: enable mkdocs search plugin to seamlessly work with i18n plugin
256282
translated_text = SEARCH_EXCLUSION + translated_text

0 commit comments

Comments
 (0)