We are building a multilingual support translator that detects a customer's language and translates their message into English for the support team, then translates the reply back. It helps small support teams handle tickets from global users without maintaining separate language-specific agents.
What you'll need
- Python 3.10 or newer
- The OpenAI SDK:
pip install openai - An Oxlo.ai API key from https://portal.oxlo.ai
Step 1: Test a basic translation
Before adding logic, I verify the connection and see how a baseline model handles a raw support ticket. I use Oxlo.ai's Qwen 3 32B because it is tuned for multilingual reasoning.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
ticket = "Hola, mi aplicación se bloquea cada vez que intento exportar un archivo PDF. ¿Pueden ayudarme?"
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": "Translate the following customer support message into English."},
{"role": "user", "content": ticket},
],
)
print(response.choices[0].message.content)
Step 2: Write a system prompt with guardrails
Basic translation loses product names and formatting. I write a system prompt that preserves technical terms, markdown, and brand voice.
SYSTEM_PROMPT = """You are a multilingual support translator.
Rules:
1. Detect the source language automatically.
2. Translate the user's message into clear, professional English.
3. Preserve all product names, file extensions, error codes, and markdown formatting.
4. Do not explain the translation. Output only the translated text.
5. If the message is already in English, return it unchanged.
Output format:
Language:
Translated: """
Step 3: Detect language and translate
Now I wrap the call in a function that accepts any ticket string and returns structured output. I ask the model to label the detected language so the agent can log it for routing.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
SYSTEM_PROMPT = """You are a multilingual support translator.
Rules:
1. Detect the source language automatically.
2. Translate the user's message into clear, professional English.
3. Preserve all product names, file extensions, error codes, and markdown formatting.
4. Do not explain the translation. Output only the translated text.
5. If the message is already in English, return it unchanged.
Output format:
Language:
Translated: """
def translate_ticket(ticket_text: str) -> dict:
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": ticket_text},
],
temperature=0.1,
)
raw = response.choices[0].message.content
lines = [line.strip() for line in raw.splitlines() if line.strip()]
result = {"language": "unknown", "translation": ""}
for line in lines:
if line.lower().startswith("language:"):
result["language"] = line.split(":", 1)[1].strip()
elif line.lower().startswith("translated:"):
result["translation"] = line.split(":", 1)[1].strip()
return result
# Test
ticket = "Bonjour, je ne parviens pas à me connecter avec mon compte SSO. L'erreur 503 apparaît."
print(translate_ticket(ticket))
Step 4: Preserve formatting and handle replies
Support threads contain code blocks and logs. I add a second function that translates the agent's English reply into the customer's language, using the language detected earlier. This keeps the conversation thread consistent.
def translate_reply(english_reply: str, target_language: str) -> str:
prompt = f"""Translate the following English support reply into {target_language}.
Preserve all markdown, code blocks, and technical terms exactly.
Reply:
{english_reply}"""
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": "You are a professional support translator."},
{"role": "user", "content": prompt},
],
temperature=0.1,
)
return response.choices[0].message.content.strip()
# Example usage
agent_reply = "Thanks for reporting this. Please try clearing your cache with `ctrl + shift + R` and let us know if error 503 persists."
print(translate_reply(agent_reply, "French"))
Step 5: Process a batch of tickets
In production, tickets arrive as a list. I loop through them, translate each one, and collect the results for the CRM or help-desk dashboard.
tickets = [
"Hola, mi aplicación se bloquea al exportar PDF.",
"Hilfe! Mein Konto wurde gesperrt und ich kann nicht auf meine Projekte zugreifen.",
"The refund button is missing on my billing page.",
]
for t in tickets:
result = translate_ticket(t)
print(f"[{result['language']}] {result['translation']}")
Run it
Putting it all together, I can run the script against a realistic mixed-language queue. The output below shows the translator handling Spanish, German, and English without extra configuration.
from openai import OpenAI
client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")
SYSTEM_PROMPT = """You are a multilingual support translator.
Rules:
1. Detect the source language automatically.
2. Translate the user's message into clear, professional English.
3. Preserve all product names, file extensions, error codes, and markdown formatting.
4. Do not explain the translation. Output only the translated text.
5. If the message is already in English, return it unchanged.
Output format:
Language:
Translated: """
def translate_ticket(ticket_text: str) -> dict:
response = client.chat.completions.create(
model="qwen-3-32b",
messages=[
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": ticket_text},
],
temperature=0.1,
)
raw = response.choices[0].message.content
lines = [line.strip() for line in raw.splitlines() if line.strip()]
result = {"language": "unknown", "translation": ""}
for line in lines:
if line.lower().startswith("language:"):
result["language"] = line.split(":", 1)[1].strip()
elif line.lower().startswith("translated:"):
result["translation"] = line.split(":", 1)[1].strip()
return result
tickets = [
"Hola, mi aplicación se bloquea cada vez que intento exportar un archivo PDF. ¿Pueden ayudarme?",
"Hilfe! Mein Konto wurde gesperrt und ich kann nicht auf meine Projekte zugreifen.",
"The refund button is missing on my billing page.",
]
for t in tickets:
result = translate_ticket(t)
print(f"[{result['language']}] {result['translation']}")
Expected output:
[Spanish] Hello, my application crashes every time I try to export a PDF file. Can you help me?
[German] Help! My account has been locked and I cannot access my projects.
[English] The refund button is missing on my billing page.
Next steps
Wire the translate_ticket function into your help-desk webhook so every incoming ticket is tagged with its detected language before an agent sees it. You can also add a function-calling step on Oxlo.ai that routes the ticket to a language-specific queue based on the detected language code.
Top comments (0)