Translate subtitles and documents from your terminal
Project description
fanyi
Translate subtitles and documents from your terminal.
fanyi is a command-line translation tool built for subtitle files. It supports SRT, ASS/SSA, and VTT formats out of the box, with additional support for plain text, Markdown, PDF, DOCX, and audio files. Powered by multiple translation engines including OpenAI, DeepL, and local models via Ollama.
Features
- Subtitle-first design - Native support for SRT, ASS/SSA, and VTT with timing preservation
- Multiple translation engines - OpenAI, DeepL, Ollama (local), or bring your own via plugins
- Batch processing - Translate entire folders of subtitle files in one command
- Context-aware translation - Use
--context-linesto give the engine dialogue context for better translations - Smart caching - Skip already-translated segments to save time and API costs
- Resumable jobs - Pick up where you left off if a translation is interrupted
- Glossary support - Define term mappings to ensure consistent translations
- Format detection - Automatically identifies file formats and encodings (including BOM)
Installation
pip install fanyi
Quick Start (30 seconds)
Translate an SRT subtitle file using the built-in mock engine (no API key needed):
fanyi subs movie.srt --target zh --engine mock
For real translations with OpenAI:
export OPENAI_API_KEY=your-key-here
fanyi subs movie.srt --target ja --engine openai
Translate all subtitles in a folder:
fanyi subs ./subtitles/ --target ko --engine openai
Supported Formats
| Format | Extension | Description |
|---|---|---|
| SRT | .srt |
SubRip subtitle format |
| ASS/SSA | .ass, .ssa |
Advanced SubStation Alpha |
| VTT | .vtt |
WebVTT subtitle format |
| Text | .txt |
Plain text files |
| Markdown | .md |
Markdown documents |
.pdf |
PDF documents (read-only extraction) | |
| DOCX | .docx |
Microsoft Word documents |
| Audio | .mp3, .wav |
Audio transcription + translation |
Supported Engines
| Engine | Description | Requires API Key |
|---|---|---|
| OpenAI | GPT-based translation with high quality | Yes |
| DeepL | Professional translation API | Yes |
| Ollama | Local LLM models (no data leaves your machine) | No |
| Mock | Built-in test engine for development/CI | No |
Configuration
Environment Variables
export OPENAI_API_KEY=your-openai-key
export DEEPL_API_KEY=your-deepl-key
export OLLAMA_HOST=http://localhost:11434
Config File
Create a config file at ~/.config/fanyi/config.yaml:
default_engine: openai
default_target: zh
engines:
openai:
model: gpt-4
temperature: 0.3
deepl:
formality: more
ollama:
model: llama3
host: http://localhost:11434
View current configuration:
fanyi config
Subtitle Translation
The subs command is optimized for subtitle workflows:
# Translate a single file
fanyi subs episode01.srt --target zh
# Translate with dialogue context for better quality
fanyi subs episode01.srt --target zh --context-lines 3
# Batch translate a folder
fanyi subs ./season1/ --target ja --engine openai
Context-Aware Translation
Use --context-lines to send surrounding dialogue lines to the engine. This helps produce translations that account for conversational flow:
fanyi subs interview.vtt --target fr --context-lines 5
CLI Commands
fanyi translate # Translate any supported file
fanyi subs # Subtitle-optimized translation
fanyi list-engines # Show available engines
fanyi list-formats # Show supported formats
fanyi config # View/manage configuration
fanyi check # Verify engine connectivity
fanyi cache # Manage translation cache
fanyi jobs # View and resume translation jobs
fanyi plugins # Manage plugins
fanyi history # View translation history
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file subfanyi-0.1.0.tar.gz.
File metadata
- Download URL: subfanyi-0.1.0.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c7578c794ed4fb13992c74ed37bb310f5d8de74ef23bfcf79212080f0d0117f
|
|
| MD5 |
ff8a2426068492198e23905a8e834c04
|
|
| BLAKE2b-256 |
d8dcf39382548d918c73b94a665dfd06749a1b1fc3192608f37a8204af6188d0
|
File details
Details for the file subfanyi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: subfanyi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 63.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2697d0d0241c3d5609ab87e097516c4c0083f5719b4dd7be2b0e797d7c06df1
|
|
| MD5 |
90ea452eb2220474507ba5a58730e9fc
|
|
| BLAKE2b-256 |
ddad5c0472fbedb768cc83b828e4323ef041436cb2a3a23066eb6fc5f5d5b717
|