Package: ai-translation

All packages Open in Cursor /Users/friedrichstr/ai-mac-studio/pdai/enrich/ai-translation
Status
Description: A package for translating scholarly XML documents from Latin to British English, preserving XML structure and handling sentence continuity across page boundaries.
Port: —
Venv: no venv
Git: not a git repo
File tree
ai-translation/
  src/
    ai_translation/
  PROJECT.yaml
  README.md
  translate_e57_pages.py
Project Goaldraft

[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:
  • [DRAFT] Define 3–5 checkable criteria for project completion
Code/Users/friedrichstr/ai-mac-studio/pdai/enrich/ai-translation
Path & Service Checks
CheckPathStatusDetail
code/Users/friedrichstr/ai-mac-studio/pdai/enrich/ai-translation✓ ok4 items, last_modified=2026-08-24
Documentation
README

AI Translation Package

A package for translating scholarly XML documents from Latin to British English, preserving XML structure and handling sentence continuity across page boundaries.

Features

  • Scholarly Translation: Accurate translation of classical and early modern scientific texts
  • XML Structure Preservation: Maintains all XML tags, attributes, and formatting exactly
  • Context Awareness: Handles sentence breaks across page boundaries
  • Consistent Terminology: Ensures consistent translation of technical terms
  • British English: Uses British spelling and terminology

Installation

pip install google-generativeai

Set the Gemini API key:

export GEMINI_API_KEY="your-api-key-here"

Usage

Basic Usage

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"
)

Parameters

  • 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)

Output

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/.

Translation Requirements

The translator maintains:

  1. XML Structure: All tags, attributes, namespaces preserved exactly
  2. Scholarly Accuracy: Consistent translation of technical terms
  3. British English: British spelling and terminology
  4. Sentence Continuity: Proper handling of sentences spanning multiple pages
  5. Footnotes: Translated while preserving structure and references

Technical Term Consistency

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"

Example

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>

Package Structure

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
Recent commits
No git history.