Skip to content

Commit 6d65408

Browse files
authored
Merge pull request #78 from hydropix/dev
prompt
2 parents d1f8fc9 + 1624238 commit 6d65408

File tree

3 files changed

+50
-53
lines changed

3 files changed

+50
-53
lines changed

prompts/prompts.py

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
3. Maintain their EXACT position in the sentence structure
1818
4. Do NOT add spaces around them unless present in the source
1919
20-
**Example with placeholders:**
20+
**Examples with placeholders (multilingual):**
21+
22+
English → Chinese:
2123
English: "This is ⟦TAG0⟧very important⟦TAG1⟧ information"
2224
✅ CORRECT: "这是⟦TAG0⟧非常重要的⟦TAG1⟧信息"
2325
❌ WRONG: "这是非常重要的信息" (placeholders removed)
2426
❌ WRONG: "这是 ⟦ TAG0 ⟧非常重要的⟦ TAG1 ⟧ 信息" (spaces added)
25-
❌ WRONG: "这是⟦TAG0_translated⟧非常重要的⟦TAG1⟧信息" (modified)
2627
"""
2728

2829

@@ -105,11 +106,25 @@ def generate_translation_prompt(
105106
Returns:
106107
str: The complete prompt formatted for translation
107108
"""
108-
source_lang = source_language.upper()
109+
# Get target-language-specific example text for output format
110+
example_texts = {
111+
"chinese": "您翻译的文本在这里" if fast_mode else "您翻译的文本在这里,所有⟦TAG0⟧标记都精确保留",
112+
"french": "Votre texte traduit ici" if fast_mode else "Votre texte traduit ici, tous les marqueurs ⟦TAG0⟧ sont préservés exactement",
113+
"spanish": "Su texto traducido aquí" if fast_mode else "Su texto traducido aquí, todos los marcadores ⟦TAG0⟧ se preservan exactamente",
114+
"german": "Ihr übersetzter Text hier" if fast_mode else "Ihr übersetzter Text hier, alle ⟦TAG0⟧-Markierungen werden genau beibehalten",
115+
"japanese": "翻訳されたテキストはこちら" if fast_mode else "翻訳されたテキストはこちら、すべての⟦TAG0⟧マーカーは正確に保持されます",
116+
"italian": "Il tuo testo tradotto qui" if fast_mode else "Il tuo testo tradotto qui, tutti i marcatori ⟦TAG0⟧ sono conservati esattamente",
117+
"portuguese": "Seu texto traduzido aqui" if fast_mode else "Seu texto traduzido aqui, todos os marcadores ⟦TAG0⟧ são preservados exatamente",
118+
"russian": "Ваш переведенный текст здесь" if fast_mode else "Ваш переведенный текст здесь, все маркеры ⟦TAG0⟧ сохранены точно",
119+
"korean": "번역된 텍스트는 여기에" if fast_mode else "번역된 텍스트는 여기에, 모든 ⟦TAG0⟧ 마커는 정확히 보존됩니다",
120+
}
121+
122+
# Try to match target language to get appropriate example
123+
target_lang_lower = target_language.lower()
124+
example_format_text = example_texts.get(target_lang_lower, "Your translated text here")
109125

110126
# Build the output format section outside the f-string to avoid backslash issues in Python 3.11
111127
additional_rules_text = "\n6. Do NOT repeat the input text or tags\n7. Preserve all spacing, indentation, and line breaks exactly as in source"
112-
example_format_text = "您翻译的文本在这里。" if fast_mode else "您翻译的文本在这里,所有⟦TAG0⟧标记都精确保留。"
113128
output_format_section = _get_output_format_section(
114129
translate_tag_in,
115130
translate_tag_out,
@@ -122,14 +137,22 @@ def generate_translation_prompt(
122137
# PROMPT - can be edited for custom usages
123138
role_and_instructions_block = f"""You are a professional {target_language} translator and writer.
124139
140+
# CRITICAL: TARGET LANGUAGE IS {target_language.upper()}
141+
142+
**YOUR TRANSLATION MUST BE WRITTEN ENTIRELY IN {target_language.upper()}.**
143+
144+
You are translating FROM {source_language} TO {target_language}.
145+
Your output must be in {target_language} ONLY - do NOT use any other language.
146+
125147
# TRANSLATION PRINCIPLES
126148
127149
**Quality Standards:**
128-
- Translate faithfully while preserving the author's voice, tone, and style
129-
- Maintain the original meaning and literary quality
150+
- Translate faithfully while preserving the author's style
151+
- Maintain the original meaning
130152
- Restructure sentences naturally in {target_language} (avoid word-by-word translation)
131153
- Adapt cultural references, idioms, and expressions to {target_language} context
132154
- Keep the exact text layout, spacing, line breaks, and indentation
155+
- **WRITE YOUR TRANSLATION IN {target_language.upper()} - THIS IS MANDATORY**
133156
134157
**Technical Content (DO NOT TRANSLATE):**
135158
- Code snippets and syntax: `function()`, `variable_name`, `class MyClass`
@@ -138,34 +161,13 @@ def generate_translation_prompt(
138161
- URLs: `https://example.com`, `www.site.org`
139162
- Programming identifiers, API names, and technical terms
140163
141-
# TRANSLATION EXAMPLES (English → Chinese)
142-
143-
**Example 1 - Topic-Comment Structure:**
144-
❌ WRONG (word-by-word): "他被他的朋友给了这本书"
145-
✅ CORRECT (natural): "他朋友送给他这本书" or "这本书是他朋友送的"
146-
English: "He was given the book by his friend"
147-
148-
**Example 2 - Idiomatic Adaptation:**
149-
❌ WRONG (literal): "下猫和狗"
150-
✅ CORRECT (adapted): "倾盆大雨" or "大雨滂沱"
151-
English: "It's raining cats and dogs"
152-
153-
**Example 3 - Cultural Context:**
154-
❌ WRONG (direct): "感恩节晚餐将在星期四"
155-
✅ CORRECT (clarified): "感恩节(美国节日)晚餐将在星期四举行"
156-
English: "Thanksgiving dinner will be on Thursday"
157-
158-
**Example 4 - Duration Expression:**
159-
❌ WRONG (awkward): "她已经工作在这个项目上三年了"
160-
✅ CORRECT (natural): "她做这个项目已经三年了"
161-
English: "She has been working on this project for three years"
164+
{'' if fast_mode else PLACEHOLDER_PRESERVATION_SECTION}
162165
163-
**Example 5 - Measure Words:**
164-
❌ WRONG (missing): "我买了三苹果"
165-
✅ CORRECT (with measure word): "我买了三个苹果"
166-
English: "I bought three apples"
166+
# FINAL REMINDER: YOUR OUTPUT LANGUAGE
167167
168-
{'' if fast_mode else PLACEHOLDER_PRESERVATION_SECTION}
168+
**YOU MUST TRANSLATE INTO {target_language.upper()}.**
169+
Your entire translation output must be written in {target_language}.
170+
Do NOT write in {source_language} or any other language - ONLY {target_language.upper()}.
169171
170172
{output_format_section}
171173
"""
@@ -231,8 +233,6 @@ def generate_subtitle_block_prompt(
231233
Returns:
232234
str: The complete prompt formatted for subtitle block translation
233235
"""
234-
source_lang = source_language.upper()
235-
236236
# Build the output format section outside the f-string to avoid backslash issues in Python 3.11
237237
subtitle_additional_rules = "\n6. Each subtitle has an index marker: [index]text - PRESERVE these markers exactly\n7. Maintain line breaks between indexed subtitles"
238238
subtitle_example_format = "[1]第一行翻译文本\n[2]第二行翻译文本"
@@ -258,6 +258,13 @@ def generate_subtitle_block_prompt(
258258
# Enhanced instructions for subtitle translation
259259
role_and_instructions_block = f"""You are a professional {target_language} subtitle translator and dialogue adaptation specialist.
260260
261+
# CRITICAL: TARGET LANGUAGE IS {target_language.upper()}
262+
263+
**YOUR SUBTITLE TRANSLATION MUST BE WRITTEN ENTIRELY IN {target_language.upper()}.**
264+
265+
You are translating subtitles FROM {source_language} TO {target_language}.
266+
Your output must be in {target_language} ONLY - do NOT use any other language.
267+
261268
# SUBTITLE TRANSLATION PRINCIPLES
262269
263270
**Quality Standards:**
@@ -266,28 +273,18 @@ def generate_subtitle_block_prompt(
266273
- Keep subtitle length readable (typically 40-42 characters per line)
267274
- Restructure sentences naturally (avoid word-by-word translation)
268275
- Maintain speaker's tone, personality, and emotion
276+
- **WRITE YOUR TRANSLATION IN {target_language.upper()} - THIS IS MANDATORY**
269277
270278
**Subtitle-Specific Rules:**
271279
- Prioritize clarity and reading speed over literal accuracy
272280
- Condense when necessary without losing meaning
273281
- Use natural, spoken {target_language} (not formal written style){custom_instructions_section}
274282
275-
# TRANSLATION EXAMPLES (Dialogue - English → Chinese)
276-
277-
**Example 1 - Natural Dialogue:**
278-
❌ WRONG: "我不能相信你做了那个" (literal/awkward)
279-
✅ CORRECT: "真不敢相信你干了这事儿" or "你竟然做了这个!"
280-
English: "I can't believe you did that"
281-
282-
**Example 2 - Colloquial Expression:**
283-
❌ WRONG: "那太酷了,伙计" (unnatural)
284-
✅ CORRECT: "太棒了!" or "真不错!"
285-
English: "That's so cool, dude"
283+
# FINAL REMINDER: YOUR OUTPUT LANGUAGE
286284
287-
**Example 3 - Condensing for Readability:**
288-
❌ WRONG: "我认为我们最好现在离开会更好" (wordy)
289-
✅ CORRECT: "我们该走了" or "现在走吧"
290-
English: "I think it would be better if we left now"
285+
**YOU MUST TRANSLATE INTO {target_language.upper()}.**
286+
Your entire subtitle translation must be written in {target_language}.
287+
Do NOT write in {source_language} or any other language - ONLY {target_language.upper()}.
291288
292289
{subtitle_output_format_section}
293290
"""

src/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class TranslationConfig:
167167
interface_type: str = "cli" # or "web"
168168
enable_colors: bool = True
169169
enable_interruption: bool = False
170-
170+
171171
@classmethod
172172
def from_cli_args(cls, args) -> 'TranslationConfig':
173173
"""Create config from CLI arguments"""

src/web/static/js/providers/model-detector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,16 @@ export const ModelDetector = {
111111
*/
112112
initialize() {
113113
const modelSelect = DomHelpers.getElement('model');
114-
const simpleModeCheckbox = DomHelpers.getElement('simpleMode');
114+
const fastModeCheckbox = DomHelpers.getElement('fastMode');
115115

116116
if (modelSelect) {
117117
modelSelect.addEventListener('change', () => {
118118
this.checkAndShowRecommendation();
119119
});
120120
}
121121

122-
if (simpleModeCheckbox) {
123-
simpleModeCheckbox.addEventListener('change', () => {
122+
if (fastModeCheckbox) {
123+
fastModeCheckbox.addEventListener('change', () => {
124124
this.checkAndShowRecommendation();
125125
});
126126
}

0 commit comments

Comments
 (0)