OpenTrans
OpenTrans is a privacy-first, local-LLM batch translation utility using Ollama. It is designed to mirror a source directory into a target language while preserving the exact file hierarchy.
Key Features
- Local-First (Ollama): Private, cost-free translation using models like Gemma, Llama 3, or DeepSeek.
- Syntax Shielding: Automatically protects code blocks (```), inline code (`), LaTeX math ($), and Markdown links from being corrupted by the LLM.
- Directory Mirroring: Recursively replicates your source folder structure in the output destination.
- Parallel Processing: Uses
ThreadPoolExecutorfor high-speed batch handling of large file sets. - Smart Caching: Uses hashing to track file changes. Only files that have been modified since the last run are sent to the LLM, saving significant time and compute resources.
- Resilient File Handling: Automatically pulls required models from Ollama with a real-time progress bar if they are missing.
Quick Usage
Simply provide the input directory and the target output directory.
opentrans ./docs ./translated_docs --config ./config.yaml
Example Output:
Target Language: Chinese
Input: /home/user/Projects/OpenTrans/docs
Output: /home/user/Projects/OpenTrans/translated_docs
Using Model: translategemma:4b
Translating Files: 100%|████████████████████████████████| 12/12 [00:45<00:00, 3.7s/file]
Complete.
Running Examples
# Translating Docusaurus
opentrans ./Example/Docusaurus/docs ./Example/Docusaurus/i18n/zh-hans/docusaurus-plugin-content-blog/current ./config.yaml
Installation
Setup
OpenTrans requires Ollama to be installed and running on your local machine.
curl -LsSf https://astral.sh/uv/install.sh | sh
uv tool install .
- Install OpenTrans
git clone https://github.com/rainstorm108/OpenTrans.git
cd OpenTrans
uv pip install .
- run
opentrans ./docs ./translated_docs --config ./config.yaml
For Developers
- Environment Setup
uv sync
source .venv/bin/activte
hatch shell
uv pip install -e .
- Running Tests
hatch test
Folder Structure
OpenTrans/
├── src/
│ └── opentrans/
│ ├── __init__.py
│ ├── main.py # CLI interface using Click
│ ├── settings.py # Translate settings
│ ├── translator.py # Translate logic
│ ├── cache_manager.py # Manages translation caching using content hashing to skip unchanged files.
│ └── hasher.py # Hash file for cache
├── tests/
│ ├── test_cache_manager.py
│ ├── test_hasher.py
│ └── test_translator.py
├── config.yaml # Global settings (model, language, etc.)
├── pyproject.toml
└── README.md
Workflow
graph TD
%% Setup Phase
Start((Start)) --> CheckRunning{Ollama Running?}
CheckRunning -- No --> Err[Error: Start Ollama]
CheckRunning -- Yes --> CheckModel{Model Exists?}
CheckModel -- No --> Pull[Download Model with Progress Bar]
Pull --> Init
CheckModel -- Yes --> Init[Load Paths & Config]
%% The Loop
Init --> NextFile{Next File?}
NextFile -- No --> Exit([Exit])
NextFile -- Yes --> IsTranslatable{File Type Supported?}
%% Branching Logic
IsTranslatable -- No --> Mirror[Copy Original File]
IsTranslatable -- Yes --> Shield[Apply Syntax Placeholders]
Shield --> Trans[Translate via Ollama API]
Trans --> Restore[Restore Protected Code/Math]
Restore --> Save[Create Dir & Save File]
Save --> NextFile
Todo
- Click-based CLI interface
- Placeholder-based syntax protection (Code/LaTeX)
- Multi-threaded parallel processing
- Implement hash caching to skip unchanged files
- Finish the Docusaurus translate script
- User Tree-sitter to replace the code blocks before translation instead of regex
- Add support for more file types
- ...
License
This project is licensed under the MIT License.
Metadata
Release files for opentrans 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| opentrans-0.1.1.tar.gz | 15.0 kB | Without provenance | Details for opentrans-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| opentrans-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for opentrans-0.1.1-py3-none-any.whl |
Total release size: 25.8 kB
Release files / opentrans-0.1.1.tar.gz
| Download URL | opentrans-0.1.1.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c27368da9f81cc731b02e9390509a0c1b35363ce5806ceecc8ed1c01a341944
|
|
BLAKE2b-256 checksum How to use checksums |
7d1d9aac9a6eec8ca52bd65744eeeeb0c36aa2242f5a6dcf8a058967676bbf20
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Release files / opentrans-0.1.1-py3-none-any.whl
| Download URL | opentrans-0.1.1-py3-none-any.whl |
|---|---|
| Size | 10.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f2d5f70465a2fbbbf0d7daaf65a774f1c5ff58f5ea386ff55d86e6966f01f81
|
|
BLAKE2b-256 checksum How to use checksums |
2a99c53987014ef913df97dd62e1639fc9ea718a2f9cc9366e5ef73990f4ca29
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.25
|
Security for opentrans 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.