---
name: contract-translation-docx
description: Translate bilingual contracts in docx format — replace one language with AI-translated target language while preserving formatting, comments, and the other language.
tags: [legal, translation, docx, contract]
---

# Contract Translation in DOCX

## When to Use
- Translating bilingual contracts (e.g., German-Chinese → English-Chinese)
- Need to preserve comments/annotations, formatting, and track changes
- Need AI-quality legal translation (not Google Translate)

## Workflow

### 1. Analyze Document Structure
- Read docx with python-docx to understand paragraph layout (bilingual alternating pattern)
- Count paragraphs per language, identify comments count
- Map which paragraphs are source language vs. target language to keep

### 2. Extract Source Language Paragraphs
- Identify source language paragraphs by content/pattern
- Extract text with paragraph index mapping for replacement later
- Count total characters to estimate batch sizes

### 3. AI Translation (delegate_task)
- Use delegate_task to translate in batches (~100 paragraphs per batch)
- Specify legal register and terminology requirements
- For German→English legal: wichtiger Grund = good cause, außerordentliche Kündigung = extraordinary termination / termination for cause, Abrechnung = statements of account
- Verify all paragraphs translated (count match)

### 4. Replace in DOCX
- Use python-docx to replace source language paragraph text with translations
- Preserve paragraph formatting (alignment, indentation, spacing)
- Update font properties (e.g., Times New Roman 12pt for English)
- Do NOT use python-docx save() on workflow-produced files (destroys XML) — only for translation-specific files

### 5. Verify
- Count paragraphs by language to confirm zero source language residual
- Verify all comments preserved (count match)
- Verify target keep-language paragraphs untouched
- OnlyOffice screenshot for visual check if possible

## Style Calibration
When a reference document exists for style matching:
- Extract terminology table from reference
- Compare translation choices (shall→应, represents and warrants→声明和保证, etc.)
- Unify font, size, and formatting to match reference
- Re-delegate for corrections if needed

## Pitfalls
- "accountings" is not idiomatic — use "statements of account"
- "Manipulation" in German legal → "Falsification" in English legal
- Keep defined terms capitalized (Licensed Know-how, Contracting Parties, this Agreement not this contract)
- Don't use Google Translate for legal documents — always use AI model translation
- Comments (annotations) are stored separately in docx XML — paragraph replacement won't affect them
