# Tasks: Add Translated PDF Export

## 1. Backend - Translation Merger Service

- [x] 1.1 Create `apply_translations()` function in `translation_service.py`
- [x] 1.2 Implement table cell translation merging logic
- [x] 1.3 Add unit tests for translation merging

## 2. Backend - PDF Generator Enhancement

- [x] 2.1 Add `generate_translated_pdf()` method to `PDFGeneratorService`
- [x] 2.2 Load translation JSON and merge with UnifiedDocument
- [x] 2.3 Handle missing translations gracefully (fallback to original)
- [x] 2.4 Add unit tests for translated PDF generation

## 3. Backend - API Endpoint

- [x] 3.1 Add `POST /api/v2/translate/{task_id}/pdf` endpoint in `translate.py`
- [x] 3.2 Validate task exists and has completed translation
- [x] 3.3 Return appropriate errors (404 if no translation, 400 if task not complete)
- [x] 3.4 Add endpoint tests

## 4. Frontend - UI Integration

- [x] 4.1 Add `downloadTranslatedPdf()` method to `apiV2.ts`
- [x] 4.2 Add "Download Translated PDF" button in `TaskDetailPage.tsx`
- [x] 4.3 Show button only when translation status is "completed"
- [x] 4.4 Add loading state during PDF generation

## 5. Testing & Validation

- [x] 5.1 End-to-end test: translate document then download PDF
- [x] 5.2 Test with Direct track document
- [x] 5.3 Test with OCR track document
- [x] 5.4 Test with document containing tables

## 6. Documentation

- [ ] 6.1 Update API documentation with new endpoint
- [ ] 6.2 Add usage example in README if applicable
