DEV Community

shashank ms
shashank ms

Posted on

LLM for Language Translation for Multilingual Support

We are building a multilingual support translator that detects a customer's language, translates their message into English for your support team, and translates your reply back into their language. This lets a small support team handle tickets from anywhere without hiring language specialists.

What you'll need

Step 1: Test basic translation with Oxlo.ai

First, I verify the connection by translating a short message. I use qwen-3-32b because Oxlo.ai lists it as a strong multilingual model, and request-based pricing means a long customer rant costs the same flat rate as a short greeting.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

test_message = "Bonjour, ma commande n'est pas encore arrivée et je commence à m'inquiéter."

response = client.chat.completions.create(
    model="qwen-3-32b",
    messages=[
        {"role": "user", "content": f"Translate this customer message to English:\n\n{test_message}"},
    ],
)

print(response.choices[0].message.content)

Step 2: Define the system prompt

A hard-coded user prompt is not enough for production. I define a system prompt that forces the model to output structured JSON with the detected language, the English translation, and a formality flag.

SYSTEM_PROMPT = """You are a multilingual support translator. Your job is to help a global support team understand customers and reply to them.

When you receive a customer message:
1. Detect the source language (ISO 639-1 code).
2. Translate the message into natural, professional English.
3. Preserve all product names, order numbers, and technical terms.
4. Judge the tone: formal, neutral, or casual.
5. Output strictly as JSON with keys: source_language, english_translation, tone.

When you receive an English reply meant for a customer:
1. Detect the target language from the provided ISO code.
2. Translate the reply into that language, matching the requested tone.
3. Preserve all product names and order numbers.
4. Output strictly as JSON with keys: target_language, customer_translation."""

Step 3: Build the incoming message translator

I wrap the API call in a function that sends the customer text to Oxlo.ai and parses the JSON response. This keeps the support dashboard code clean.

import json
from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

def translate_incoming(customer_text: str):
    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": f"Translate this customer message:\n\n{customer_text}"},
        ],
        response_format={"type": "json_object"},
    )
    return json.loads(response.choices[0].message.content)

# Example usage
result = translate_incoming("Hola, recibí el producto equivocado. Necesito un reemplazo urgente.")
print(json.dumps(result, indent=2, ensure_ascii=False))

Step 4: Build the outgoing reply translator

Now I add the reverse path. The support agent writes in English, and the function translates it back into the customer's language while matching the tone we detected earlier.

def translate_outgoing(english_reply: str, target_language: str, tone: str):
    prompt = (
        f"Translate this English reply for a customer.\n"
        f"Target language: {target_language}\n"
        f"Tone: {tone}\n\n"
        f"{english_reply}"
    )
    response = client.chat.completions.create(
        model="qwen-3-32b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": prompt},
        ],
        response_format={"type": "json_object"},
    )
    return json.loads(response.choices[0].message.content)

# Example usage
reply = translate_outgoing(
    "I am sorry for the mix-up. We are sending the correct item now with expedited shipping.",
    target_language="es",
    tone="formal",
)
print(json.dumps(reply, indent=2, ensure_ascii=False))

Step 5: Handle a full ticket thread

In production, you want one helper that manages the whole loop. This class stores the customer's language and tone after the first message, then reuses them for every reply.

class MultilingualSupportAgent:
    def __init__(self, api_client, model="qwen-3-32b"):
        self.client = api_client
        self.model = model
        self.source_language = None
        self.tone = None

    def receive(self, customer_text: str):
        response = self.client.chat.completions.create(
            model=self.model,
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": f"Translate this customer message:\n\n{customer_text}"},
            ],
            response_format={"type": "json_object"},
        )
        result = json.loads(response.choices[0].message.content)
        self.source_language = result["source_language"]
        self.tone = result["tone"]
        return result

    def reply(self, english_text: str):
        if not self.source_language:
            raise ValueError("No customer message received yet.")
        prompt = (
            f"Translate this English reply for a customer.\n"
            f"Target language: {self.source_language}\n"
            f"Tone: {self.tone}\n\n"
            f"{english_text}"
        )
        response = self.client.chat.completions.create(
            model=self.model,
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": prompt},
            ],
            response_format={"type": "json_object"},
        )
        return json.loads(response.choices[0].message.content)

# Run a full thread
agent = MultilingualSupportAgent(client)

incoming = agent.receive("Guten Tag, mein Konto wurde ohne Vorwarnung gesperrt.")
print("English for support team:", incoming["english_translation"])

outgoing = agent.reply(
    "Thank you for reaching out. Your account was temporarily locked after three failed login attempts. "
    "I have unlocked it and sent a password reset link to your email."
)
print("Reply for customer:", outgoing["customer_translation"])

Run it

Here is the complete script I run from the terminal. It processes three realistic support tickets in different languages and prints both the English summary for the agent and the final reply for the customer.

from openai import OpenAI
import json

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

SYSTEM_PROMPT = """You are a multilingual support translator. Your job is to help a global support team understand customers and reply to them.

When you receive a customer message:
1. Detect the source language (ISO 639-1 code).
2. Translate the message into natural, professional English.
3. Preserve all product names, order numbers, and technical terms.
4. Judge the tone: formal, neutral, or casual.
5. Output strictly as JSON with keys: source_language, english_translation, tone.

When you receive an English reply meant for a customer:
1. Detect the target language from the provided ISO code.
2. Translate the reply into that language, matching the requested tone.
3. Preserve all product names and order numbers.
4. Output strictly as JSON with keys: target_language, customer_translation."""

class MultilingualSupportAgent:
    def __init__(self, api_client, model="qwen-3-32b"):
        self.client = api_client
        self.model = model
        self.source_language = None
        self.tone = None

    def receive(self, customer_text: str):
        response = self.client.chat.completions.create(
            model=self.model,
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": f"Translate this customer message:\n\n{customer_text}"},
            ],
            response_format={"type": "json_object"},
        )
        result = json.loads(response.choices[0].message.content)
        self.source_language = result["source_language"]
        self.tone = result["tone"]
        return result

    def reply(self, english_text: str):
        if not self.source_language:
            raise ValueError("No customer message received yet.")
        prompt = (
            f"Translate this English reply for a customer.\n"
            f"Target language: {self.source_language}\n"
            f"Tone: {self.tone}\n\n"
            f"{english_text}"
        )
        response = self.client.chat.completions.create(
            model=self.model,
            messages=[
                {"role": "system", "content": SYSTEM_PROMPT},
                {"role": "user", "content": prompt},
            ],
            response_format={"type": "json_object"},
        )
        return json.loads(response.choices[0].message.content)

tickets = [
    "Bonjour, je voudrais savoir comment appliquer le code promo SUMMER2025.",
    "Здравствуйте, я получил поврежденный товар. Хочу оформить возврат.",
    "Hola, ¿pueden ayudarme a cambiar mi dirección de envío antes de que salga el paquete?",
]

for text in tickets:
    print("=" * 60)
    agent = MultilingualSupportAgent(client)
    inc = agent.receive(text)
    print("Detected language:", inc["source_language"])
    print("English:", inc["english_translation"])
    print("Tone:", inc["tone"])

    out = agent.reply(
        "No problem at all. I have updated your request and you should see the changes reflected within ten minutes."
    )
    print("Reply:", out["customer_translation"])
    print()

When I run this, the output looks similar to the following (exact wording varies by model temperature):

============================================================
Detected language: fr
English: Hello, I would like to know how to apply the SUMMER2025 promo code.
Tone: formal
Reply: Bonjour, pas de problème du tout. J'ai mis à jour votre demande et vous devriez voir les changements reflétés dans les dix prochaines minutes.

============================================================
Detected language: ru
English: Hello, I received a damaged product. I want to arrange a return.
Tone: formal
Reply: Здравствуйте, совсем не проблема. Я обновил ваш запрос, и вы должны увидеть изменения в течение десяти минут.

============================================================
Detected language: es
English: Hello, can you help me change my shipping address before the package leaves?
Tone: casual
Reply: Hola, no hay problema. He actualizado tu solicitud y deberías ver los cambios reflejados en unos diez minutos.

Wrap up

This translator runs on Oxlo.ai, so long customer messages with attachments or screenshots do not inflate your bill the way token-based providers do. You can see the flat request pricing at https://oxlo.ai/pricing.

Two concrete next steps: wire this agent into your helpdesk via webhooks so it translates tickets automatically, or swap qwen-3-32b for kimi-k2.6 if you need vision support to translate text inside images.

Top comments (0)