Overview
Batch translation processes multiple text segments or entire documents in a single API call. This is significantly more efficient than translating one segment at a time, and it enables bulk processing of government correspondence, policy documents, and regulatory filings.
Multi-Segment Batch
Send up to 50 text segments in a single request. Each segment is translated independently with the same domain and language pair settings.
curl -X POST http://localhost:8012/api/v1/translate/batch \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"texts": [
"يجب على جميع الجهات الحكومية الالتزام بمعايير الأمن السيبراني",
"تم اعتماد الميزانية السنوية للوزارة",
"يرجى مراجعة الشروط والأحكام المرفقة"
],
"source_lang": "ar",
"target_lang": "en",
"domain": "administrative"
}'
Response:
{
"translations": [
{
"id": "tr-001",
"source_text": "يجب على جميع الجهات الحكومية الالتزام بمعايير الأمن السيبراني",
"translated_text": "All government entities must comply with cybersecurity standards",
"source_lang": "ar",
"target_lang": "en",
"domain": "administrative",
"quality_score": 0.92,
"created_at": "2024-01-15T10:30:00Z"
},
{
"id": "tr-002",
"source_text": "تم اعتماد الميزانية السنوية للوزارة",
"translated_text": "The ministry's annual budget has been approved",
"source_lang": "ar",
"target_lang": "en",
"domain": "administrative",
"quality_score": 0.95,
"created_at": "2024-01-15T10:30:01Z"
},
{
"id": "tr-003",
"source_text": "يرجى مراجعة الشروط والأحكام المرفقة",
"translated_text": "Please review the attached terms and conditions",
"source_lang": "ar",
"target_lang": "en",
"domain": "administrative",
"quality_score": 0.94,
"created_at": "2024-01-15T10:30:01Z"
}
],
"total": 3,
"domain": "administrative"
}
Batch Limits
| Constraint | Value |
|---|---|
| Maximum segments per batch | 50 |
| Maximum characters per segment | 50,000 |
Document Translation
Upload an entire document file for translation. Translate extracts text, segments it, translates each segment with domain awareness, and returns the complete translated content.
curl -X POST http://localhost:8012/api/v1/translate/document \
-H "Authorization: Bearer $TOKEN" \
-F "file=@ministry_circular.pdf" \
-F "source_lang=ar" \
-F "target_lang=en" \
-F "domain=administrative"
Response:
{
"id": "doc-a1b2c3",
"filename": "ministry_circular.pdf",
"source_lang": "ar",
"target_lang": "en",
"domain": "administrative",
"status": "completed",
"total_segments": 45,
"translated_segments": 45,
"translated_text": "...",
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:30:12Z"
}
Progress Tracking
Document translation returns segment counts for progress tracking. The total_segments field shows how many segments were extracted, and translated_segments shows how many have been processed. For large documents, poll the status endpoint to track completion.
Supported Formats
Document translation accepts PDF, DOCX, and TXT files. The text extraction pipeline handles Arabic RTL content and mixed-language documents.
Quality Scores
Each translated segment includes an optional quality_score (0.0 to 1.0) that reflects the model's confidence in the translation. Scores above 0.9 indicate high confidence. Lower scores may warrant human review, especially for legal and regulatory content.
Translation History
All translations -- single, batch, and document -- are recorded in the translation history. Filter by domain, language pair, and date range:
curl "http://localhost:8012/api/v1/translate/history?domain=legal&page=1&page_size=20" \
-H "Authorization: Bearer $TOKEN"
Response:
{
"translations": [...],
"total": 142,
"page": 1,
"page_size": 20
}
Language Detection
When the source language is unknown, use auto detection:
curl -X POST http://localhost:8012/api/v1/translate/detect \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
-d '{
"text": "All government entities must comply with cybersecurity standards"
}'
{
"language": "en",
"confidence": 0.98,
"script": "Latin"
}