Prompt
How do I batch translate thousands of records without losing formatting?
Latest observation
To batch translate thousands of records without losing formatting, the key is to separate content from structure, translate only the text, and then reinsert it into the original template/markup.
Best practice workflow
1) Keep the original structure intact
Use a format that preserves structure, such as:
- HTML/XML/JSON/XLIFF
- Spreadsheet columns with one text field per cell
- Document formats that support placeholders or tags
Avoid sending raw copied text where line breaks, bullets, placeholders, or tags can get corrupted.
2) Extract only translatable text
Before translation, split each record into:
- Text to translate
- Non-translatable elements like:
- IDs
- URLs
- product codes
- HTML tags
- placeholders like
{name},%s,{{value}} - formatting markers
Example:
{
"title": "Welcome, {name}",
"body": "<p>Click <strong>here</strong> to continue.</p>"
}
Translate only:
Welcome, {name}Click here to continue.
Preserve:
{name}<p>,<strong>
3) Use placeholder protection
Replace protected items with tokens before translation:
{{PLACEHOLDER_1}}<1>...</1>__URL__
After translation, restore the original values.
This helps prevent the translator or model from changing:
- variables
- HTML tags
- special formatting
4) Translate in chunks, not all at once
For thousands of records:
- split into batches by size, not just count
- keep each batch within token/character limits
- maintain a consistent prompt/template
Good batching strategy:
- 50–200 records per batch depending on length
- group by language/domain
- avoid mixing very short and very long records if possible
5) Ask for structured output
Require the translator to return the same structure as the input.
For example, if input is JSON, output should also be JSON with identical keys.
Example instruction:
Translate only the values, preserve all keys, placeholders, HTML tags, and line breaks exactly. Return valid JSON only.
This reduces formatting drift.
6) Validate and compare output
After translation:
- check that all placeholders are preserved
- verify tags are balanced
- compare record counts and keys
- run schema validation for JSON/XML
- inspect sample outputs
Automated checks can catch:
- missing braces
- broken HTML
- altered numbering
- line break changes
7) Use a translation memory if possible
If records repeat similar phrases, use:
- translation memory
- glossary
- term base
This improves consistency and reduces formatting errors.
Recommended approaches by data type
If your data is in spreadsheets
- Keep each translatable field in its own column
- Export to CSV/XLSX
- Translate only selected columns
- Reimport while preserving IDs and metadata
If your data contains HTML/XML
- Use tag-aware translation tools or APIs
- Protect tags with placeholders
- Validate output with an HTML/XML parser
If your data is JSON
- Translate only string values
- Do not change keys
- Preserve arrays/objects exactly
- Run JSON validation afterward
If your data is plain text with formatting markers
- Preserve markdown, bullets, numbering, and inline code
- Tell the translator not to alter:
**bold**# headings`code`- lists and indentation
Example prompt for AI translation
Translate the following records into French.
Preserve all placeholders, HTML tags, markdown, numbers, and line breaks exactly.
Do not change keys or IDs.
Return the same JSON structure, translated values only.
Tools that help
Depending on your workflow, consider:
- CAT tools: SDL Trados, memoQ, Smartcat
- Localization platforms: Phrase, Lokalise, Crowdin
- Scripts: Python for tokenizing/restoring placeholders
- Validation libraries: JSON/XML/HTML parsers
Simple rule of thumb
If you want to preserve formatting, never translate the final rendered text directly.
Translate the content layer while keeping the structure layer untouched.
If you want, I can also show you:
- a Python script for batch translation with placeholder preservation, or
- a prompt template for translating JSON/CSV safely.