| 59 | |
| 60 | |
| 61 | def get_prompt( |
| 62 | lang_prompt_content: str, |
| 63 | old_translation: str | None, |
| 64 | language: str, |
| 65 | language_name: str, |
| 66 | original_content: str, |
| 67 | additional_instructions: str, |
| 68 | ) -> str: |
| 69 | general_prompt_with_additional_instructions = general_prompt.replace( |
| 70 | "[placeholder_for_additional_instructions]", additional_instructions |
| 71 | ) |
| 72 | prompt_segments = [ |
| 73 | general_prompt_with_additional_instructions, |
| 74 | lang_prompt_content, |
| 75 | ] |
| 76 | if old_translation: |
| 77 | prompt_segments.extend( |
| 78 | [ |
| 79 | "There is an existing previous translation for the original English content, that may be outdated.", |
| 80 | "Update the translation only where necessary:", |
| 81 | "- If the original English content has added parts, also add these parts to the translation.", |
| 82 | "- If the original English content has removed parts, also remove them from the translation, unless you were instructed earlier to not do that in specific cases.", |
| 83 | "- If parts of the original English content have changed, also change those parts in the translation.", |
| 84 | "- If the previous translation violates current instructions, update it.", |
| 85 | "- Otherwise, preserve the original translation LINE-BY-LINE, AS-IS.", |
| 86 | "Do not:", |
| 87 | "- rephrase or rewrite correct lines just to improve the style.", |
| 88 | "- add or remove line breaks, unless the original English content changed.", |
| 89 | "- change formatting or whitespace unless absolutely required.", |
| 90 | "Only change what must be changed. The goal is to minimize diffs for easier human review.", |
| 91 | "UNLESS you were instructed earlier to behave different, there MUST NOT be whole sentences or partial sentences in the updated translation, which are not in the original English content, and there MUST NOT be whole sentences or partial sentences in the original English content, which are not in the updated translation. Remember: the updated translation shall be IN SYNC with the original English content.", |
| 92 | "Previous translation:", |
| 93 | f"%%%\n{old_translation}%%%", |
| 94 | ] |
| 95 | ) |
| 96 | prompt_segments.extend( |
| 97 | [ |
| 98 | f"Translate to {language} ({language_name}).", |
| 99 | "Original content:", |
| 100 | f"%%%\n{original_content}%%%", |
| 101 | ] |
| 102 | ) |
| 103 | return "\n\n".join(prompt_segments) |
| 104 | |
| 105 | |
| 106 | @app.command() |