Skip to content

Commit b9122b3

Browse files
committed
feat: add prompt for mdx frontmatter sections
1 parent c605572 commit b9122b3

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

packages/translate/src/openai.ts

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,32 @@ async function translateChunk(
5454
const textLength = chunk.length;
5555
const prompt = `
5656
Translate the following documentation from English to ${langConfig.name}.
57-
The document being translated is of MDX file type, which means there are components in the text. Please ensure component closing tags are not missing, for example:
58-
\`<AppOnly> </AppOnly>\` and \`<PagesOnly> </PagesOnly>\`.
59-
Keep all code blocks, markdown formatting, HTML tags, and variables unchanged.
60-
Do not translate text within \`\`\` code blocks or inline \`code\`.
61-
Do not translate URLs or file paths.
62-
Maintain the original paragraph structure and heading levels.
63-
Provide only the translated content without any introduction, prefixes, or meta-explanations about the translation. Output just the translation itself.
57+
58+
General rules:
59+
• The document is MDX format - ensure all component tags are properly closed (e.g., \`<AppOnly> </AppOnly>\` \`<PagesOnly> </PagesOnly>\` )
60+
• Keep unchanged:
61+
- All code blocks
62+
- Markdown formatting
63+
- HTML tags
64+
- Variables
65+
- Text within \`\`\` code blocks or inline \`code\`
66+
- URLs and file paths
67+
• Maintain the original paragraph structure and heading levels
68+
69+
MDX Frontmatter rules:
70+
• For sections between --- marks, do not start a value with inline code
71+
• Example:
72+
- Original:
73+
description: API reference for \`getStaticProps\`. Learn how to use \`getStaticProps\` to generate static pages with Next.js.
74+
- INCORRECT translation:
75+
description: \`getStaticProps\` API 参考文档。了解如何使用 \`getStaticProps\` 在 Next.js 中生成静态页面。
76+
- CORRECT translation:
77+
description: API \`getStaticProps\` 参考文档。了解如何使用 \`getStaticProps\` 在 Next.js 中生成静态页面。
78+
79+
Output format:
80+
• Provide only the translated content
81+
• No introduction, prefixes, or meta-explanations
82+
• Just the translation itself
6483
6584
${context}
6685

0 commit comments

Comments
 (0)