A modern, AI-powered language translation tool with text-to-speech capabilities
Features • Demo • Installation • Usage • Architecture • Contributing
- Overview
- Features
- Demo
- Architecture
- Technology Stack
- Installation
- Usage
- Project Structure
- Configuration
- Testing
- Deployment
- Troubleshooting
- Contributing
- License
- Acknowledgments
- Contact
The AI Language Translation Tool is a sophisticated web application built with Python and Streamlit that provides real-time language translation capabilities for over 100 languages. It combines modern translation APIs with text-to-speech functionality to deliver an intuitive and powerful translation experience.
- 🔤 100+ Languages - Support for major world languages
- 🎯 Auto-Detection - Automatically identify source language
- 🔊 Text-to-Speech - Hear translations in target language
- 💾 Smart Caching - Fast response times with intelligent caching
- 📜 Translation History - Track your recent translations
- ⚡ Quick Phrases - One-click common phrase translations
- 📱 Responsive Design - Works on desktop, tablet, and mobile
- 🌙 Dark Mode - Easy on the eyes
This project was developed as part of the CodeAlpha AI Internship Program (Task #1: Language Translation Tool), demonstrating proficiency in:
- AI/ML integration
- Full-stack web development
- API integration and error handling
- User interface/experience design
- Production-ready code practices
| Feature | Description |
|---|---|
| Multi-Language Translation | Translate text between 100+ languages with high accuracy |
| Auto Language Detection | Automatically identify the source language of your text |
| Text-to-Speech (TTS) | Listen to translations with natural-sounding voice synthesis |
| Translation History | Access your last 10 translations with timestamps |
| Quick Phrases | Instant translation of common phrases (Hello, Thank you, etc.) |
| Batch Translation | Translate multiple lines of text simultaneously |
| Smart Caching | LRU cache with TTL for improved performance |
| Copy to Clipboard | Easy copying of translated text |
| Language Swap | Quickly swap source and target languages |
- Multi-Provider Support - Google Translate & Deep Translator with automatic fallback
- Retry Logic - Exponential backoff for failed requests
- Input Validation - Comprehensive text validation and sanitization
- Error Handling - User-friendly error messages
- Session Management - Maintains state across interactions
- Export History - Download translation history as JSON
- Dark Mode - Toggle between light and dark themes
The clean and intuitive main interface with language selectors and translation areas
Real-time translation with source and target language display
View and manage your recent translations with timestamps
Comprehensive settings sidebar with cache statistics and feature toggles
┌─────────────────────────────────────────────────────────────┐
│ Frontend Layer │
│ (Streamlit UI) │
│ ┌──────────────────────────────────────────────────────┐ │
│ │ • Language Selectors │ │
│ │ • Input/Output Text Areas │ │
│ │ • Action Buttons (Translate, Copy, TTS) │ │
│ │ • History Display │ │
│ │ • Cache Statistics │ │
│ └──────────────────────────────────────────────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Business Logic Layer │
│ (Core Services) │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ Translation │ │ Language │ │
│ │ Service │ │ Detection │ │
│ │ • Validation │ │ • Auto-detect │ │
│ │ • Caching │ │ • Confidence │ │
│ │ • Retry Logic │ │ Scoring │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ TTS Service │ │ Cache Manager │ │
│ │ • Audio Gen │ │ • LRU Cache │ │
│ │ • MP3 Output │ │ • TTL Expiry │ │
│ │ • Base64 │ │ • Statistics │ │
│ └──────────────────┘ └──────────────────┘ │
└─────────────────────────┬───────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────┐
│ Integration Layer │
│ (External APIs) │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ googletrans │ │ deep-translator │ │
│ │ (Primary API) │ │ (Fallback API) │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ gTTS │ │ pyttsx3 │ │
│ │ (TTS Provider) │ │ (Local TTS - Future) │ │
│ └──────────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────┘
User Input → Validation → Cache Check → API Call → Result Processing → UI Display
↓ ↓
Cache Hit Cache Miss
↓ ↓
Return Cached Fetch from API
↓
Store in Cache
┌──────────────┐
│ Streamlit │
│ App │
└──────┬───────┘
│
├──→ Translation Service
│ ├──→ Validator
│ ├──→ Cache Manager
│ └──→ API Provider (googletrans/deep-translator)
│
├──→ Language Detector
│ └──→ googletrans Detector
│
└──→ TTS Service
└──→ gTTS Generator
| Category | Technology | Version | Purpose |
|---|---|---|---|
| Language | Python | 3.10+ | Core programming language |
| Framework | Streamlit | 1.28+ | Web application framework |
| Package Manager | UV | Latest | Fast Python package management |
| Library | Version | Purpose |
|---|---|---|
googletrans |
4.0.0rc1 | Primary translation API (unofficial Google Translate) |
deep-translator |
1.11.4+ | Fallback translation provider |
gTTS |
2.4.0+ | Google Text-to-Speech for audio generation |
pyttsx3 |
2.90+ | Offline TTS (future feature) |
| Library | Version | Purpose |
|---|---|---|
httpx |
0.25.0+ | Modern HTTP client for API calls |
python-dotenv |
1.0.0+ | Environment variable management |
pydantic |
2.4.0+ | Data validation and settings management |
pydantic-settings |
2.0.3+ | Settings management with Pydantic |
| Tool | Purpose |
|---|---|
pytest |
Unit testing framework |
pytest-cov |
Code coverage reporting |
black |
Code formatting |
ruff |
Fast Python linter |
mypy |
Static type checking |
- Pattern: Three-Tier Architecture (Presentation, Business Logic, Data/Integration)
- Design: Service-Oriented Architecture (SOA)
- State Management: Streamlit Session State
- Caching: LRU Cache with TTL
- Error Handling: Try-Catch with Retry Logic
- Python 3.10 or higher
- pip or UV package manager
- Git (for cloning repository)
- Internet connection (for API access)
# 1. Clone the repository
git clone https://github.com/yourusername/language-translation-tool.git
cd language-translation-tool
# 2. Install UV (if not already installed)
curl -LsSf https://astral.sh/uv/install.sh | sh
# 3. Create virtual environment and install dependencies
uv venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
uv pip install -e .
# 4. Set up environment variables (optional)
cp .env.example .env
# Edit .env if you have API keys
# 5. Run the application
streamlit run src/app.py# 1. Clone the repository
git clone https://github.com/yourusername/language-translation-tool.git
cd language-translation-tool
# 2. Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# 3. Install dependencies
pip install -r requirements.txt
# 4. Set up environment variables (optional)
cp .env.example .env
# 5. Run the application
streamlit run src/app.py# 1. Clone the repository
git clone https://github.com/yourusername/language-translation-tool.git
cd language-translation-tool
# 2. Build Docker image
docker build -t translation-tool .
# 3. Run container
docker run -p 8501:8501 translation-tool
# 4. Open browser
# Visit: http://localhost:8501# Test that all services load correctly
python test_services_interactive.py
# Expected output:
# ✓ Translation service initialized
# ✓ Language detection available
# ✓ TTS service initialized
# ✅ All services working!-
Launch the application:
streamlit run src/app.py
-
Open your browser to
http://localhost:8501 -
Select languages:
- Source: Choose language or use "Auto-detect"
- Target: Choose desired translation language
-
Enter text in the input area
-
Click "🔄 Translate"
-
View results in the translation output area
1. Set source language to "Auto-detect"
2. Enter text in any language
3. Click "🔍 Detect Language" to see detected language
4. Click "🔄 Translate" to translate
1. Complete a translation
2. Click "🔊 Listen" button
3. Audio player appears with pronunciation
4. Adjust volume and replay as needed
1. Complete a translation
2. Click "📋 Copy" button
3. Code block appears with translated text
4. Click copy icon in code block or use Ctrl+C
1. Scroll to "⚡ Quick Phrases" section
2. Click any phrase button (e.g., "👋 Hello")
3. Phrase auto-fills in input area
4. Click translate
1. Scroll to "📋 Batch Translation" section
2. Enter multiple lines (one per line)
3. Click "🔄 Translate All"
4. View all translations in expandable sections
1. Scroll to "📜 Recent Translations"
2. Click "View History" expander
3. See last 10 translations with timestamps
4. Click "📥 Export History" to download JSON
5. Click "🗑️ Clear History" to reset
1. Open sidebar (click arrow if collapsed)
2. Click "🌙 Toggle Dark Mode"
3. Interface switches to dark theme
4. Click again to return to light mode
language-translation-tool/
├── .github/
│ └── workflows/
│ └── ci.yml # CI/CD pipeline
├── src/
│ ├── __init__.py
│ ├── app.py # Main Streamlit application
│ ├── services/
│ │ ├── __init__.py
│ │ ├── translator.py # Translation service
│ │ ├── language_detector.py # Language detection
│ │ └── tts_service.py # Text-to-speech
│ ├── utils/
│ │ ├── __init__.py
│ │ ├── cache.py # Caching logic
│ │ ├── validators.py # Input validation
│ │ └── constants.py # Language codes & constants
│ └── config/
│ ├── __init__.py
│ └── settings.py # Configuration management
├── tests/
│ ├── __init__.py
│ ├── test_translator.py # Translation tests
│ ├── test_validators.py # Validation tests
│ ├── test_cache.py # Cache tests
│ └── test_services.py # Service integration tests
├── assets/
│ └── screenshots/ # Application screenshots
│ ├── banner.png
│ ├── main-interface.png
│ ├── translation-demo.png
│ ├── history-view.png
│ └── sidebar-features.png
├── docs/
│ ├── ARCHITECTURE.md # Detailed architecture docs
│ ├── API.md # API documentation
│ └── CONTRIBUTING.md # Contribution guidelines
├── .streamlit/
│ └── config.toml # Streamlit configuration
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── Dockerfile # Docker configuration
├── pyproject.toml # UV project configuration
├── requirements.txt # pip dependencies
├── LICENSE # MIT License
├── README.md # This file
└── test_services_interactive.py # Interactive testing script
| File | Purpose |
|---|---|
src/app.py |
Main Streamlit application with UI components |
src/services/translator.py |
Multi-provider translation with retry logic |
src/services/language_detector.py |
Automatic language detection |
src/services/tts_service.py |
Text-to-speech audio generation |
src/utils/cache.py |
LRU cache implementation with TTL |
src/utils/validators.py |
Input validation and sanitization |
src/utils/constants.py |
Language codes and application constants |
src/config/settings.py |
Pydantic-based configuration |
pyproject.toml |
Project metadata and dependencies |
requirements.txt |
Python package dependencies |
.env.example |
Example environment variables |
Create a .env file in the project root:
# Application Settings
APP_TITLE="AI Language Translation Tool"
APP_ICON="🌍"
MAX_TEXT_LENGTH=5000
DEFAULT_SOURCE_LANG=auto
DEFAULT_TARGET_LANG=es
# Cache Configuration
CACHE_ENABLED=true
CACHE_TTL_HOURS=24
CACHE_MAX_SIZE=1000
# Text-to-Speech Settings
TTS_ENABLED=true
TTS_PROVIDER=gtts
TTS_SPEED=1.0
# Development Settings
DEBUG=false
LOG_LEVEL=INFO
# Feature Flags
ENABLE_TRANSLATION_HISTORY=true
ENABLE_LANGUAGE_DETECTION=true
ENABLE_COPY_BUTTON=true
ENABLE_TTS_BUTTON=true
# API Configuration (Optional)
GOOGLE_TRANSLATE_API_KEY=your_api_key_here
AZURE_TRANSLATOR_KEY=your_azure_key_here
AZURE_TRANSLATOR_REGION=eastus.streamlit/config.toml:
[server]
port = 8501
address = "localhost"
headless = false
[browser]
gatherUsageStats = false
[theme]
primaryColor = "#3498db"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f8f9fa"
textColor = "#2c3e50"
font = "sans serif"# Run complete test suite
pytest
# Run with coverage
pytest --cov=src --cov-report=html
# Run specific test file
pytest tests/test_translator.py -v
# Run specific test class
pytest tests/test_services.py::TestTranslationService -v# Test all services interactively
python test_services_interactive.py
# Test complete workflow
python test_complete_app.py- Translation works for different languages
- Auto-detect identifies languages correctly
- TTS generates and plays audio
- Copy button works (shows code block)
- Swap languages button swaps correctly
- History tracks translations
- Cache improves performance
- Dark mode toggles properly
- Quick phrases auto-fill input
- Batch translation processes multiple lines
- Export history downloads JSON
Solution:
# Reinstall googletrans
pip uninstall googletrans
pip install googletrans==4.0.0rc1Solution:
- Check browser audio permissions
- Ensure gTTS is installed:
pip install gTTS - Try different browser (Chrome recommended)
Solution:
- Clear browser cache (Ctrl+Shift+R)
- Restart Streamlit app
- Check if toggle is in sidebar
Solution:
- Install pyperclip:
pip install pyperclip - Or use native code block copy icon
- On Linux: Install xclip or xsel
Solution:
- Check
.env:CACHE_ENABLED=true - Clear cache from sidebar
- Restart application
Enable debug logging:
# In .env
DEBUG=true
LOG_LEVEL=DEBUGView logs:
streamlit run src/app.py --logger.level=debugWe welcome contributions! Here's how to get started:
# 1. Fork the repository on GitHub
# 2. Clone your fork
git clone https://github.com/YOUR-USERNAME/language-translation-tool.git
cd language-translation-tool
# 3. Create a branch
git checkout -b feature/your-feature-name
# 4. Install dev dependencies
uv pip install -e ".[dev,test]"
# 5. Make your changes
# 6. Run tests
pytest
# 7. Format code
black src/
ruff check src/
# 8. Commit and push
git add .
git commit -m "Add: your feature description"
git push origin feature/your-feature-name
# 9. Create Pull Request on GitHub- Follow PEP 8 style guide
- Add tests for new features
- Update documentation
- Write clear commit messages
- Keep PRs focused and small
- 🌐 Add more translation providers
- 🎨 Improve UI/UX design
- 🧪 Increase test coverage
- 📚 Enhance documentation
- 🐛 Fix bugs
- ⚡ Performance optimization
- 🌍 Add more languages
This project is licensed under the MIT License - see the LICENSE file for details.
MIT License
Copyright (c) 2025 [pforprogrammer]
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
- CodeAlpha - For the internship opportunity and project guidance
- Streamlit Team - For the amazing web framework
- Google Translate - For translation API access
- Open Source Community - For the libraries and tools
- Streamlit - Web application framework
- googletrans - Translation API
- deep-translator - Multi-provider translation
- gTTS - Text-to-speech
- Pydantic - Data validation
- UV - Fast Python package manager
This project was inspired by the need for a simple, fast, and reliable translation tool that combines modern AI capabilities with an intuitive user interface.
[Hassan Ahmed]
- GitHub: @pforprogrammer
- LinkedIn: Hassan Ahmed
- Email: agentic.hassan.ai@gmail.com
- Website: www.codealpha.tech
- WhatsApp: +91 8052293611
- Email: services@codealpha.tech
- Core translation functionality
- Auto language detection
- Text-to-speech
- Translation history
- Dark mode
- Batch translation
- Offline mode with local models
- PDF/Document translation
- Browser extension
- Mobile app (React Native)
- API endpoint for developers
- Multi-user support with accounts
Made with ❤️ by pforprogrammer aka Hassan Ahmed for the CodeAlpha AI Internship Program



