Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

6 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Code Translator πŸ”„

CI/CD Tests Python PyQt6 FastAPI Docker License

A professional code translator that intelligently translates code between programming languages using AI. Features a modern desktop GUI, web API, and CLI interface.

Code Translator Demo

✨ Features

πŸ€– AI-Powered Translation

  • 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

🌐 10+ Languages Supported

  • Python
  • JavaScript / TypeScript
  • Java / Kotlin
  • Swift
  • C++
  • Go
  • Rust
  • Ruby

πŸ–₯️ Multiple Interfaces

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

⚑ Smart Features

  • Auto-detect source language
  • Syntax highlighting
  • Translation history
  • Clipboard integration
  • Offline mode with basic translations

πŸš€ Quick Start

Desktop GUI

# 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

CLI Mode

# 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

Web API

# Install web dependencies
pip install fastapi uvicorn

# Run the server
uvicorn src.web.app:app --reload

# Open http://localhost:8000 in your browser

πŸ“¦ Installation

Requirements

  • Python 3.9 or higher
  • pip (Python package manager)

Full Installation

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

Platform-Specific Notes

macOS

# Global hotkeys require accessibility permissions
# Grant permission when prompted on first run

Linux

# Requires X11 for transparency features
sudo apt-get install libxkbcommon-x11-0 libxcb-cursor0

πŸ”§ Configuration

API Keys

Configure in Settings dialog or via environment variables:

Settings Location

  • Windows: %APPDATA%\CodeTranslator\settings.json
  • macOS/Linux: ~/.config/CodeTranslator/settings.json

🌐 Web API Reference

Endpoints

Method Endpoint Description
GET /api/health Health check
GET /api/languages List supported languages
POST /api/detect Detect language
POST /api/translate Translate code

Example: 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"
  }'

Response

{
  "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.

☁️ Deployment

Deploy to Railway

# Login to Railway CLI
railway login

# Initialize and deploy
railway init
railway up

# Set environment variables
railway variables set OPENAI_API_KEY=your-key

Deploy to Vercel

# Install Vercel CLI
npm i -g vercel

# Deploy (create vercel.json first)
vercel deploy

Docker

The 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 -d

For more Docker configuration options, see the Dockerfile and docker-compose.yml in the repository.

πŸ§ͺ Development

Setup Development Environment

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

Project Structure

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

Running Tests

# 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

⌨️ Keyboard Shortcuts (Desktop)

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

🀝 Contributing

We welcome contributions! Please see our Contributing Guide.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing)
  5. Open a Pull Request

πŸ“ License

MIT License - see LICENSE for details.

πŸ“š Examples

Check out the examples/ folder for sample code files demonstrating translations:

  • python_example.py - Python β†’ JavaScript translation
  • javascript_example.js - JavaScript β†’ Python translation
  • complex_class.py - Advanced OOP patterns

πŸ“Š Benchmarks

See BENCHMARKS.md for:

  • Translation accuracy by language pair
  • Speed benchmarks per provider
  • Supported language features matrix

πŸ—οΈ Built With

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

About

Professional desktop code translator with AI integration

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages