Prompt

How do I translate product reviews through an API and keep the original formatting?

Technology / API Platforms1 observationLast seen Nov 2, 2026

Latest observation

Nov 2, 2026OpenAI APIWeb search: off

To translate product reviews through an API and preserve the original formatting, the key is to treat the review as structured text, not just a plain string. That means you should preserve:

  • line breaks
  • bullet points
  • emojis
  • punctuation
  • HTML/Markdown tags
  • placeholders like {name}, %s, <a href=...>

Recommended approach

1. Use a translation API that supports formatting preservation

Some translation APIs have features for preserving tags or markup, for example:

  • DeepL API: supports tag_handling=html or xml
  • Google Cloud Translate: you may need to pre-process tags yourself
  • Microsoft Translator: can also be used with text segmentation and markup handling

If your reviews are in HTML, XML, or Markdown, choose an API that can explicitly preserve tags.


2. Wrap formatting in tags or placeholders

If the review contains formatting like this:

Great product!

Pros:
- Fast
- Lightweight

Cons:
- Battery life could be better

Send it as-is if the API preserves line breaks. If not, convert it to a structured form first, such as:

<p>Great product!</p>
<p>Pros:</p>
<ul>
  <li>Fast</li>
  <li>Lightweight</li>
</ul>
<p>Cons:</p>
<ul>
  <li>Battery life could be better</li>
</ul>

Then translate with HTML tag preservation enabled.


3. Preserve placeholders and special tokens

Before translation, protect any variable text:

  • {username}
  • {product_name}
  • %s
  • {{count}}

Example strategy:

  1. Replace placeholders with temporary tokens:
    • {username} → __USERNAME__
  2. Translate the text
  3. Restore the original placeholders afterward

This prevents the translator from changing them.


4. Send reviews individually or in batches

For best formatting preservation:

  • Translate each review separately
  • Keep metadata separate from text
  • Use batching only if the API clearly supports segmentation

Example JSON input:

{
  "review_id": "123",
  "language": "en",
  "text": "Great product!\n\nPros:\n- Fast\n- Lightweight"
}

Then store the original and translated versions separately.


5. Example with DeepL-style HTML preservation

If the review is HTML:

import requests

url = "https://api.deepl.com/v2/translate"
data = {
    "auth_key": "YOUR_API_KEY",
    "text": "<p>Great product!</p><p>Fast shipping.</p>",
    "target_lang": "DE",
    "tag_handling": "html"
}

response = requests.post(url, data=data)
print(response.json())

This tells the API to preserve HTML tags while translating the text inside them.


6. If your reviews are plain text, preserve formatting manually

For plain text reviews, formatting is usually represented by:

  • newlines
  • spacing
  • markdown syntax

You can:

  • split by paragraphs
  • translate paragraph by paragraph
  • rejoin with the same separators

Example:

paragraphs = review.split("\n\n")
translated_paragraphs = [translate(p) for p in paragraphs]
result = "\n\n".join(translated_paragraphs)

This helps keep paragraph structure intact.


Best practices

  • Do not translate HTML tags or markdown syntax
  • Escape user-generated content before sending it to translation
  • Validate translated output to ensure placeholders are unchanged
  • Keep a copy of the original review
  • Test with edge cases: emojis, URLs, URLs with query strings, mixed languages

A practical workflow

  1. Receive review text
  2. Detect/identify formatting type:
    • plain text
    • HTML
    • Markdown
  3. Protect placeholders and special tokens
  4. Send to translation API with markup preservation enabled
  5. Restore placeholders if needed
  6. Save translated text with original formatting preserved

If you want, I can show you:

  • a Python example
  • a Node.js example
  • or a solution for HTML/Markdown reviews specifically

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.