Trilekha (त्रिलेखा) is a multilingual document translation tool built for the Google TMT Hackathon 2026, Track 2: File Translation Tool.
The name comes from two Nepali roots: tri (त्रि) meaning three, and lekha (लेखा) meaning writing or script. Three languages. One tool.
Trilekha translates PDF, DOCX, CSV, and TSV documents between English, Nepali, and Tamang using the Google Trilingual Machine Translation (TMT) API developed by the Information and Language Processing Lab at Kathmandu University.
Deployed: trilekha.streamlit.app
No setup needed. Upload a file, choose your language pair, download the translation.
- Translates
.pdf,.docx,.csv, and.tsvfiles while returning the same file format. - Preserves document structure and layout as far as possible, including PDF page geometry, DOCX paragraphs/tables, and CSV/TSV cell positions.
- Sends text to TMT sentence by sentence, matching the API's sentence-level translation requirement.
- Supports English, Nepali, and Tamang language pairs.
- Handles Nepali PDFs that use legacy fonts by repairing extracted text with Likhit before translation.
┌─────────────────────────────────────────────────────┐
│ Streamlit Frontend │
│ app.py │
│ • File upload, language selection, progress, download│
└───────────────────────┬─────────────────────────────┘
│
┌─────────────▼──────────────┐
│ File Parser │
│ backend/parsers/*.py │
│ │
│ Extracts text blocks with │
│ layout/position metadata │
└─────────────┬──────────────┘
│
┌─────────────▼──────────────┐
│ Sentence Splitter │
│ backend/utils/sentence_splitter.py │
│ │
│ NLTK for English │
│ Punctuation for Ne/Tmg │
└─────────────┬──────────────┘
│
┌─────────────▼──────────────┐
│ TMT API Client │
│ backend/translators/*.py │
│ │
│ One sentence per request │
│ Retry + rate limit aware │
└─────────────┬──────────────┘
│
┌─────────────▼──────────────┐
│ File Reconstructor │
│ backend/reconstructors/*.py │
│ │
│ Rebuilds output in same │
│ format as original │
└─────────────────────────────┘
- Parse — extract text blocks with layout metadata (coordinates, font size, style)
- Split — break each block into individual sentences using NLTK (English) or punctuation rules (Nepali/Tamang)
- Translate — send each sentence to the TMT API with rate limiting and retry logic
- Reconstruct — reassemble translated sentences into the original file format
PDF
Uses PyMuPDF (fitz) for both parsing and writing. Original text areas are redacted with a white fill, then translated text is drawn over the original page — preserving all non-text content (images, backgrounds, lines, columns). Devanagari text uses TextWriter for proper conjunct shaping via the font's GSUB/GPOS tables.
DOCX
Uses python-docx. Iterates all paragraphs and table cells. Replaces text in-place while preserving run-level formatting (bold, italic, font size, heading styles).
CSV/TSV
Uses Python's built-in csv module. Reads the full grid including empty cells, translates non-empty cells, writes back to the same row/column positions with the same delimiter.
trilekha/
├── app.py # Streamlit entrypoint and orchestration
│
├── frontend/
│ ├── __init__.py
│ ├── constants.py # UI strings, language options, limits, theme tokens
│ └── ui.py # Streamlit UI components
│
├── backend/
│ ├── parsers/
│ │ ├── __init__.py
│ │ ├── pdf_parser.py # PyMuPDF-based PDF text extraction
│ │ ├── pdf_text_repair.py # Likhit-backed legacy Nepali PDF text repair
│ │ ├── docx_parser.py # python-docx paragraph + table parser
│ │ └── csv_parser.py # CSV/TSV cell extractor
│ │
│ ├── reconstructors/
│ │ ├── __init__.py
│ │ ├── pdf_writer.py # Redact + overlay translated text on original PDF
│ │ ├── docx_writer.py # In-place paragraph/cell replacement
│ │ └── csv_writer.py # Grid reconstruction with translations
│ │
│ ├── translators/
│ │ ├── __init__.py
│ │ ├── tmt_client.py # Single sentence API call with retry
│ │ ├── batch.py # Generator loop over sentence list
│ │ ├── config.py # Settings from environment variables
│ │ └── models.py # TranslationRequest / TranslationResponse
│ │
│ ├── utils/
│ │ └── sentence_splitter.py # Shared NLTK + punctuation sentence splitter
│ │
│ └── __init__.py
│
├── fonts/
│ └── NotoSansDevanagari-Regular.ttf # Required for Devanagari PDF rendering
│
├── .env.example # Template for environment variables
├── .gitignore
├── logo.webp # Light-mode app logo and page icon
├── logo-light.webp # Dark-mode app logo and page icon
├── logo.ico # Additional icon asset
├── pyproject.toml # Package definition for editable install
├── requirements.txt
├── LICENSE # MIT License
└── README.md
- Python 3.12 or newer
pip- A TMT API key
git clone https://github.com/notashwinii/trilekha.git
cd trilekhapython3.12 -m venv venv
# Linux / macOS
source venv/bin/activate
# Windows
venv\Scripts\activatepip install -r requirements.txt
pip install -e .cp .env.example .envOpen .env and fill in your values:
TMT_API_URL=https://tmt.ilprl.ku.edu.np/lang-translate
TMT_API_KEY=team_xxxxxxxxxxxxxxxx
# Optional tuning
TMT_REQUEST_TIMEOUT_SECONDS=10
TMT_RETRY_COUNT=3
TMT_RETRY_BACKOFF_SECONDS=0.5
TMT_REQUEST_SPACING_SECONDS=0.35
TMT_RATE_LIMIT_RETRY_SECONDS=60
TRILEKHA_DEV_LOGS=falseThe repository includes fonts/NotoSansDevanagari-Regular.ttf, which is required for correct Nepali and Tamang rendering in translated PDFs. If the file is missing, download it:
mkdir -p fonts
wget "https://github.com/googlefonts/noto-fonts/raw/main/hinted/ttf/NotoSansDevanagari/NotoSansDevanagari-Regular.ttf" \
-O fonts/NotoSansDevanagari-Regular.ttfstreamlit run app.pyOpen http://localhost:8501 in your browser.
| From | To | API codes |
|---|---|---|
| English | Nepali | en → ne |
| English | Tamang | en → tmg |
| Nepali | English | ne → en |
| Nepali | Tamang | ne → tmg |
| Tamang | English | tmg → en |
| Tamang | Nepali | tmg → ne |
| Package | Purpose |
|---|---|
streamlit |
Web frontend |
pymupdf |
PDF parsing and writing |
python-docx |
DOCX parsing and writing |
nltk |
English sentence tokenisation |
python-dotenv |
Environment variable loading |
requests |
TMT API HTTP calls |
likhit |
Legacy Nepali PDF text repair |
MIT License. See LICENSE for details.
All submitted work was developed specifically for the Google TMT Hackathon 2026.