A professional code translator that intelligently translates code between programming languages using AI. Features a modern desktop GUI, web API, and CLI interface.
- Multiple AI Providers: OpenAI GPT-4, Anthropic Claude, Google Gemini
- Intelligent Translation: Handles paradigm differences, not just syntax
- Confidence Scores: Know how reliable each translation is
- Automatic Fallback: Seamlessly switches providers if one fails
- Python
- JavaScript / TypeScript
- Java / Kotlin
- Swift
- C++
- Go
- Rust
- Ruby
- Desktop GUI - Beautiful PyQt6 app with transparency support
- Web API - FastAPI backend with interactive frontend
- CLI - Command-line tool for scripts and pipelines
- VS Code Extension - Coming soon! (preview)
- Auto-detect source language
- Syntax highlighting
- Translation history
- Clipboard integration
- Offline mode with basic translations
# Clone and install
git clone https://github.com/maximilliangrand/code-translator.git
cd code-translator
pip install -r requirements.txt
# Run the desktop app
python src/main.py# Translate a file
python -m code_translator --from python --to javascript input.py
# Auto-detect source language
python -m code_translator --to rust input.py -o output.rs
# Translate from stdin
echo "print('hello')" | python -m code_translator --from python --to java
# List supported languages
python -m code_translator --list-languages# Install web dependencies
pip install fastapi uvicorn
# Run the server
uvicorn src.web.app:app --reload
# Open http://localhost:8000 in your browser- Python 3.9 or higher
- pip (Python package manager)
# Clone repository
git clone https://github.com/maximilliangrand/code-translator.git
cd code-translator
# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install all dependencies
pip install -r requirements.txt
# Set up API keys (optional - for AI providers)
# Add to environment or use the settings dialog in GUI
export OPENAI_API_KEY="your-key"
export ANTHROPIC_API_KEY="your-key"
export GOOGLE_API_KEY="your-key"# Global hotkeys require accessibility permissions
# Grant permission when prompted on first run# Requires X11 for transparency features
sudo apt-get install libxkbcommon-x11-0 libxcb-cursor0Configure in Settings dialog or via environment variables:
OPENAI_API_KEY- Get from platform.openai.comANTHROPIC_API_KEY- Get from console.anthropic.comGOOGLE_API_KEY- Get from makersuite.google.com
- Windows:
%APPDATA%\CodeTranslator\settings.json - macOS/Linux:
~/.config/CodeTranslator/settings.json
| Method | Endpoint | Description |
|---|---|---|
| GET | /api/health |
Health check |
| GET | /api/languages |
List supported languages |
| POST | /api/detect |
Detect language |
| POST | /api/translate |
Translate code |
curl -X POST http://localhost:8000/api/translate \
-H "Content-Type: application/json" \
-d '{
"code": "def hello(): print(\"Hello!\")",
"source_lang": "Python",
"target_lang": "JavaScript"
}'{
"translated_code": "function hello() {\n console.log(\"Hello!\");\n}",
"source_lang": "Python",
"target_lang": "JavaScript",
"confidence": 0.95,
"provider_used": "anthropic"
}π Full API documentation: See docs/API.md for complete reference with more examples.
# Login to Railway CLI
railway login
# Initialize and deploy
railway init
railway up
# Set environment variables
railway variables set OPENAI_API_KEY=your-key# Install Vercel CLI
npm i -g vercel
# Deploy (create vercel.json first)
vercel deployThe easiest way to run the web API:
# Quick start with Docker
docker build -t code-translator .
docker run -p 8000:8000 -e OPENAI_API_KEY=your-key code-translator
# Or use Docker Compose (recommended)
docker-compose up -d
# With environment file
echo "OPENAI_API_KEY=your-key" > .env
docker-compose up -dFor more Docker configuration options, see the Dockerfile and docker-compose.yml in the repository.
# Install dev dependencies
pip install -r requirements.txt
# Run tests
python -m pytest tests/ -v
# Format code
black src/ tests/
# Type checking
mypy src/
# Lint
flake8 src/code-translator/
βββ src/
β βββ __main__.py # CLI entry point
β βββ main.py # Desktop app entry point
β βββ gui/ # PyQt6 GUI components
β βββ translator/ # Translation engine
β β βββ translator_engine.py
β β βββ offline_translator.py
β βββ web/ # FastAPI web app
β β βββ app.py
β β βββ templates/
β βββ config/ # Configuration management
β βββ providers/ # AI provider implementations
β βββ utils/ # Utilities
βββ tests/ # Test suite
βββ .github/workflows/ # CI/CD pipelines
βββ requirements.txt
βββ README.md
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ -v --cov=src --cov-report=html
# Run specific test file
python -m pytest tests/test_api_compatibility.py -v| Shortcut | Action |
|---|---|
Ctrl+Shift+T |
Show/Hide window |
Ctrl+Enter |
Translate code |
Ctrl+D |
Toggle dark/light theme |
Ctrl+H |
Show history |
Ctrl+S |
Save to favorites |
We welcome contributions! Please see our Contributing Guide.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing) - Open a Pull Request
MIT License - see LICENSE for details.
Check out the examples/ folder for sample code files demonstrating translations:
python_example.py- Python β JavaScript translationjavascript_example.js- JavaScript β Python translationcomplex_class.py- Advanced OOP patterns
See BENCHMARKS.md for:
- Translation accuracy by language pair
- Speed benchmarks per provider
- Supported language features matrix
| Technology | Purpose |
|---|---|
| Python 3.9+ | Core language |
| PyQt6 | Desktop GUI framework |
| FastAPI | Web API framework |
| Pydantic | Data validation |
| OpenAI API | AI translation provider |
| Anthropic API | AI translation provider |
| Google AI | AI translation provider |
Made with β€οΈ by maximilliangrand
