You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DEV: Translate raw content instead of cooked content (#245)
Raw is in general much smaller than cooked. Cooked tends to have a lot of html when it includes things like pulled oneboxes, mentions, images.
The gigantic cooked content also increases the amount of time it takes to translate content.
In sending raw, we can cook the translated content after it returns from the API. This also helps with sanitisation.
Copy file name to clipboardExpand all lines: app/services/discourse_ai/translator.rb
+14-16Lines changed: 14 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,14 @@
3
3
moduleDiscourseAi
4
4
classTranslator
5
5
PROMPT_TEMPLATE=<<~TEXT.freeze
6
-
You are a highly skilled linguist of many languages and have expert knowledge in HTML.
7
-
Your task is to identify the language of the text I provide and accurately translate it into this language locale "%{target_language}" while preserving the meaning, tone, and nuance of the original text.
8
-
The text may or may not contain html tags. If they do, preserve them.
9
-
Maintain proper grammar, spelling, and punctuation in the translated version.
10
-
You will find the text between <input></input> XML tags.
11
-
Include your translation between <output></output> XML tags.
12
-
Do not write explanations.
6
+
You are an expert translator specializing in converting Markdown content from any source language to target locale "%{target_language}". Your task is to:
7
+
1. Translate the content accurately while preserving all Markdown formatting elements
8
+
2. Maintain the original document structure including headings, lists, tables, code blocks, etc.
9
+
3. Preserve all links, images, and other media references without translation
10
+
4. Handle code snippets appropriately - don't translate variable names, functions, or syntax within code blocks (```), but translate comments
11
+
5. When encountering technical terminology, provide the accepted target language term if it exists, or transliterate if no equivalent exists, with the original term in parentheses
12
+
6. For ambiguous terms or phrases, choose the most contextually appropriate translation
13
+
7. You are being consumed via an API, only EVER return the translated text, do not return any other information
0 commit comments