ai-translation/
src/
ai_translation/
PROJECT.yaml
README.md
translate_e57_pages.py
[DRAFT — edit this] A package for translating scholarly XML documents from Latin to British English, preserving XML structure and handling sentence continuity across page boundaries. Inferred stage: development. Define the specific deliverable, success state, and timeline.
Success criteria:| Code | /Users/friedrichstr/ai-mac-studio/pdai/enrich/ai-translation |
| Check | Path | Status | Detail |
|---|---|---|---|
| code | /Users/friedrichstr/ai-mac-studio/pdai/enrich/ai-translation | ✓ ok | 4 items, last_modified=2026-08-24 |
A package for translating scholarly XML documents from Latin to British English, preserving XML structure and handling sentence continuity across page boundaries.
pip install google-generativeai
Set the Gemini API key:
export GEMINI_API_KEY="your-api-key-here"
from ai_translation.translator import translate_xml_pages
translate_xml_pages(
xml_folder="E57/pdai/E57/xml",
start_page=3,
end_page=10,
target_lang="en",
model="gemini-3.8-flash"
)
xml_folder: Path to folder containing XML page files (e.g., page_003.xml, page_004.xml)start_page: First page number to translate (inclusive)end_page: Last page number to translate (inclusive)target_lang: Target language code (default: "en")model: Gemini model name (default: "gemini-3.8-flash")api_key: Optional API key (defaults to GEMINI_API_KEY environment variable)Translated XML files are saved to {xml_folder}/../xml-{target_lang}/ directory. For example, if xml_folder is E57/pdai/E57/xml and target_lang is "en", output will be in E57/pdai/E57/xml-en/.
The translator maintains:
Key terms are translated consistently: - "Fluxus ac Refluxus Maris" → "Flux and Reflux of the Sea" or "Tides" - "Phaenomenon/Phaenomena" → "Phenomenon/Phenomena" - "vis/vires" → "force/forces" - "Terra" → "Earth" - "Luna" → "Moon" - "Sol" → "Sun"
Input XML (page_005.xml):
<page pidx="5" xmlns="http://ai-scholar.org/ocr/1.0">
<meta model="gemini-3.8-flash" instruction_template="unified_ocr_schema" lang="lat" />
<content>
<partext><p><parno>8</parno> Quamvis autem certis viribus Lunae ac Soli tribuendis...</p></partext>
</content>
</page>
Output XML (xml-en/page_005.xml):
<page pidx="5" xmlns="http://ai-scholar.org/ocr/1.0">
<meta model="gemini-3.8-flash" instruction_template="unified_ocr_schema" lang="en" />
<content>
<partext><p><parno>8</parno> Although, however, by attributing certain forces to the Moon and Sun...</p></partext>
</content>
</page>
ai-translation/
├── src/
│ └── ai_translation/
│ ├── __init__.py
│ ├── translator.py # Main translation logic
│ ├── xml_processor.py # XML parsing and structure preservation
│ └── instruction_templates.py # Translation instruction templates
└── README.md