Skip to content

A platform for community discussion. Free, open, simple.

FIX: Steer translation agents away from ASCII quotes in structured output (#42131)

Rafael dos Santos Silva491e2461668a
diff --git a/plugins/discourse-ai/lib/agents/post_raw_translator.rb b/plugins/discourse-ai/lib/agents/post_raw_translator.rb
index 6aa6f8cce3a..74ab04d1e54 100644
--- a/plugins/discourse-ai/lib/agents/post_raw_translator.rb
+++ b/plugins/discourse-ai/lib/agents/post_raw_translator.rb
@@ -20,7 +20,7 @@ module DiscourseAi
5. For ambiguous terms or phrases, do not translate word-for-word in isolation. Derive the intended meaning from the full context of the document before choosing a translation.
6. Ensure the translation only contains the original language and the target language.
7. Match the tone and register of the source text. If the source is informal and conversational, use informal address forms and a casual tone in the target language. Do not default to formal address (e.g. German Sie, French vous) unless the source text is itself formal.
- 8. For any quoted text, use the target language's native quotation marks — for example German „…", French «…», Japanese 「…」 — rather than ASCII quotes.
+ 8. For any quoted text, use the target language's native quotation marks — for example German „…“, French «…», Japanese 「…」 — rather than ASCII quotes.
Follow these instructions on what NOT to do:
9. Do not translate code snippets or programming language names, but ensure that any comments within the code are translated. Code can be represented in ``` or in single ` backticks or in <code> HTML tags.
diff --git a/plugins/discourse-ai/lib/agents/short_text_translator.rb b/plugins/discourse-ai/lib/agents/short_text_translator.rb
index e436f15f73e..3339eace97b 100644
--- a/plugins/discourse-ai/lib/agents/short_text_translator.rb
+++ b/plugins/discourse-ai/lib/agents/short_text_translator.rb
@@ -16,6 +16,7 @@ module DiscourseAi
2. Keep the translated content close to the original length
3. Translation maintains the original meaning
4. Preserve any Markdown, HTML elements, links, parenthesis, or newlines
+ 5. Never use ASCII double quotes (") inside the translation. For quoted text, use the target language's native quotation marks — for example German „…“, French «…», Japanese 「…」
The text to translate will be provided in JSON format with the following structure:
{"content": "Text to translate", "target_locale": "Target language code"}
@@ -43,6 +44,10 @@ module DiscourseAi
{ output: "Perguntas e Respostas" }.to_json,
],
[{ content: "Minecraft", target_locale: "fr" }.to_json, { output: "Minecraft" }.to_json],
+ [
+ { content: %(Click "Reply"), target_locale: "fr" }.to_json,
+ { output: "Cliquez sur « Répondre »" }.to_json,
+ ],
]
end
end
diff --git a/plugins/discourse-ai/lib/agents/topic_title_translator.rb b/plugins/discourse-ai/lib/agents/topic_title_translator.rb
index 14550f353de..8fce41b405c 100644
--- a/plugins/discourse-ai/lib/agents/topic_title_translator.rb
+++ b/plugins/discourse-ai/lib/agents/topic_title_translator.rb
@@ -16,6 +16,7 @@ module DiscourseAi
3. Attempt to keep the translated title length close to the original when possible.
4. Match the tone and register of the source text. Do not default to formal address unless the source is itself formal.
5. For ambiguous terms or phrases, do not translate word-for-word in isolation. Derive the intended meaning from the full context of the title before choosing a translation.
+ 6. Never use ASCII double quotes (") inside the translation. For quoted text or UI labels, use the target language's native quotation marks — for example German „…“, French «…», Japanese 「…」.
The text to translate will be provided in JSON format with the following structure:
{"content": "Title to translate", "target_locale": "Target language code"}
@@ -61,6 +62,13 @@ module DiscourseAi
"Heathrow closed: flight disruption expected to continue in coming days, says London airport management",
}.to_json,
],
+ [
+ {
+ content: "Permanently Delete does not show (even after 5 minutes)",
+ target_locale: "de",
+ }.to_json,
+ { output: "„Endgültig löschen“ wird nicht angezeigt (auch nach 5 Minuten)" }.to_json,
+ ],
]
end
end