A modern, responsive web application for real-time translation using OpenAI's GPT models. Features voice recognition, text-to-speech, and a clean modular architecture.
- ๐ Multi-language Support - Auto-detect source language or choose from supported languages
- ๐ค Voice Recognition - Speech-to-text input with browser API
- ๐ Text-to-Speech - Listen to translations with natural voices
- ๐ฑ Responsive Design - Mobile-first design that works on all devices
- ๐พ History Management - Keep track of recent translations
- โก Live Translation - Real-time translation as you type
- ๐จ Modern UI - Clean, intuitive interface with smooth animations
- ๐ง Modular Architecture - Well-organized, maintainable codebase
- ๐ Performance Optimized - Fast loading with lazy loading and caching
- Frontend: Vanilla JavaScript (ES6+), CSS3, HTML5
- API: OpenAI GPT-3.5-turbo
- Build Tools: ESLint, Prettier, http-server
- Browser APIs: Web Speech API, Speech Synthesis API, localStorage
/
โโโ index.html # Main HTML file
โโโ main.js # Application entry point
โโโ package.json # Dependencies and scripts
โโโ css/ # Modular CSS files
โ โโโ variables.css # CSS custom properties
โ โโโ base.css # Reset & fundamental styles
โ โโโ header.css # Header & branding
โ โโโ translation-container.css # Main interface
โ โโโ controls.css # Control panel & interactive elements
โ โโโ history.css # Translation history
โ โโโ notifications.css # Toast notifications
โ โโโ responsive.css # Mobile optimizations
โโโ js/ # JavaScript modules
โ โโโ ApiManager.js # OpenAI API integration
โ โโโ VoiceController.js # Speech recognition & synthesis
โ โโโ TranslationEngine.js # Core translation logic
โ โโโ HistoryManager.js # Translation history
โ โโโ UIController.js # UI interactions & notifications
โ โโโ EventManager.js # Event handling & shortcuts
โ โโโ PerformanceUtils.js # Performance optimizations
โโโ original/ # Backup of original files
## ๐ Quick Start
### Prerequisites
- Node.js >= 16.0.0
- OpenAI API key
- Modern web browser with ES6+ support
### Installation
1. **Clone the repository**
```bash
git clone https://github.com/jimmyhanh/.git
cd
-
Install dependencies
npm install
-
Start the development server
npm start
-
Open your browser Navigate to
http://localhost:3000 -
Configure your API key
- Enter your OpenAI API key in the settings panel
- The key is stored securely in localStorage
npm start- Start development servernpm run dev- Start with auto-reload (no cache)npm run lint- Check code qualitynpm run lint:fix- Fix linting issues automaticallynpm run format- Format code with Prettiernpm run validate- Run linting and format checksnpm run build- Validate and build for production
- Enter your OpenAI API key in the settings panel
- Type or paste text in the source language box
- Select source and target languages
- Click "Translate" or enable live translation
- ๐ค Voice Input: Click the microphone to speak your text
- ๐ Text-to-Speech: Click the play button to hear translations
- ๐ Language Swap: Click the swap arrow to reverse languages
Ctrl/Cmd + Enter- Translate textCtrl/Cmd + K- Clear all textCtrl/Cmd + M- Toggle voice input
The application uses a modular architecture with clear separation of concerns:
- ApiManager - Handles all OpenAI API communication with retry logic
- VoiceController - Manages speech recognition and text-to-speech
- TranslationEngine - Core translation logic and language management
- HistoryManager - Persistent storage and retrieval of translations
- UIController - UI state management and user interactions
- EventManager - Centralized event handling and keyboard shortcuts
- PerformanceUtils - Performance optimizations and utilities
The app uses localStorage for configuration. No server-side environment variables needed.
Update the language maps in TranslationEngine.js:
this.languageNames = {
'auto': 'Auto Detect',
'en': 'English',
'es': 'Spanish', // Add new language
// ... more languages
};- Fetch API
- ES6 Modules
- CSS Custom Properties
- Web Speech API (optional, for voice features)
- Lazy Loading - Resources loaded on demand
- Debounced Translation - Prevents excessive API calls
- Memory Management - Efficient event listener cleanup
- Optimized Animations - Respects user motion preferences
- Caching - Service worker for offline functionality
- API keys stored locally in browser
- No server-side data storage
- HTTPS required for voice features
- Input validation and sanitization
- Rate limiting and retry logic
- ESLint - Code linting with recommended rules
- Prettier - Consistent code formatting
- JSDoc - Comprehensive code documentation
- Error Boundaries - Robust error handling
- Test with different languages and text lengths
- Verify voice recognition works in supported browsers
- Test responsive design on various screen sizes
- Validate offline functionality with service worker
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
- Follow the existing code style
- Add JSDoc comments for new functions
- Update tests for new features
- Ensure responsive design compatibility
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for the GPT API
- Font Awesome for icons
- Google Fonts for typography
- Web Speech API for voice features
A modern, real-time translation application powered by OpenAI's GPT models, supporting both text and voice input with speech synthesis capabilities.
- Real-time Translation: Translate text instantly as you type
- Voice Input: Speak in any supported language using Web Speech API
- Text-to-Speech: Listen to translations with natural voice synthesis
- Multi-language Support: Vietnamese, English, Japanese, German, Chinese
- Auto Language Detection: Automatically detect source language
- Bidirectional Translation: Easy language swapping with one click
- Live Translation Mode: Toggle real-time translation as you type
- Translation History: Keep track of recent translations
- Offline Storage: API key and history stored locally
- Responsive Design: Works perfectly on desktop, tablet, and mobile
- Keyboard Shortcuts: Quick actions with keyboard shortcuts
- Copy to Clipboard: Easy sharing of translations
- Modern UI: Beautiful gradient design with smooth animations
- Modern web browser with JavaScript enabled
- OpenAI API key (Get one here)
- Internet connection for API calls
-
Clone or Download
git clone https://github.com/yourusername/polyglot-translator.git cd polyglot-translator -
Open the Application
- Open
index.htmlin your web browser - Or serve it using a local web server:
# Using Python python -m http.server 8000 # Using Node.js npx serve . # Using PHP php -S localhost:8000
- Open
-
Configure API Key
- Enter your OpenAI API key in the settings panel
- Click "Save" to store it locally
- Your key is stored securely in your browser's local storage
-
Start Translating!
- Type text in the source language box
- Select source and target languages
- Click "Translate" or enable live translation
- Use voice input by clicking the microphone button
- Enter text in the left text area
- Select source and target languages
- Click the "Translate" button
- View the translation in the right text area
- Click the microphone button (๐ค)
- Speak clearly in your chosen language
- The speech will be converted to text automatically
- Translation happens instantly if live mode is enabled
- Toggle the "Live Translation" switch
- Start typing in the source text area
- Translation updates automatically after 1 second pause
- Perfect for real-time conversations
- Click the play button (
โถ๏ธ ) next to any text area - Listen to the pronunciation in the selected language
- Supports all target languages with native voice synthesis
Ctrl/Cmd + Enter: Translate textCtrl/Cmd + K: Clear all textCtrl/Cmd + M: Toggle voice inputTab: Navigate between elementsEnter: Save API key (when focused on key input)
| Language | Code | Voice Input | Text-to-Speech |
|---|---|---|---|
| English | en |
โ | โ |
| Vietnamese | vi |
โ | โ |
| Japanese | ja |
โ | โ |
| German | de |
โ | โ |
| Chinese | zh |
โ | โ |
- Visit OpenAI Platform
- Create an account or sign in
- Generate a new API key
- Copy the key and paste it in PolyGlot's settings
- Ensure you have sufficient API credits
- Microphone Access: Required for voice input
- Local Storage: Used to save API key and history
- Clipboard Access: For copy translation feature
PolyGlot is fully responsive and optimized for mobile devices:
- Touch-friendly interface
- Adaptive layout for different screen sizes
- Mobile-optimized voice input
- Gesture support for common actions
- API Key: Stored locally in your browser, never sent to third parties
- Translation Data: Sent only to OpenAI for processing
- No Server: Runs entirely in your browser
- No Analytics: No tracking or data collection
- Open Source: Full transparency of code
To add support for new languages, modify the languageNames object in script.js:
this.languageNames = {
'auto': 'Auto Detect',
'en': 'English',
'vi': 'Vietnamese',
'ja': 'Japanese',
'de': 'German',
'zh': 'Chinese',
'fr': 'French', // Add new language
'es': 'Spanish' // Add new language
};Also update the HTML select options in index.html.
Modify styles.css to customize:
- Color scheme (change CSS custom properties)
- Layout and spacing
- Animations and transitions
- Mobile breakpoints
Translation not working:
- Check your OpenAI API key
- Verify internet connection
- Check browser console for errors
- Ensure you have API credits
Voice input not working:
- Allow microphone permissions
- Check if using HTTPS (required for speech API)
- Try different browsers (Chrome/Edge recommended)
Text-to-speech not working:
- Check browser compatibility
- Ensure audio is not muted
- Try different languages
| Feature | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| Basic Translation | โ | โ | โ | โ |
| Voice Input | โ | โ | โ | โ |
| Text-to-Speech | โ | โ | โ | โ |
| Live Translation | โ | โ | โ | โ |
- Model: GPT-3.5-turbo
- Max Tokens: 1000 per translation
- Temperature: 0.3 (for consistent translations)
- Average cost: ~$0.002 per translation
- 1000 translations โ $2.00
- Voice input adds no extra cost
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes
- Test thoroughly
- Submit a pull request
- Clone the repository
- Make changes to HTML, CSS, or JavaScript files
- Test in multiple browsers
- Ensure mobile compatibility
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for providing the powerful GPT models
- Web Speech API for voice recognition capabilities
- Font Awesome for beautiful icons
- Google Fonts for typography
- Contributors who help improve PolyGlot
- Issues: GitHub Issues
- Documentation: This README file
- Email: support@polyglot-translator.com
- Initial release with full translation features
- Voice input and text-to-speech support
- Live translation mode
- Multi-language support
- Responsive design
- Translation history
- Offline translation support
- Document translation
- Image text translation
- Conversation mode
- Translation quality rating
- Custom voice selection
- Dark/light theme toggle
- Export translation history
Made with โค๏ธ using OpenAI's GPT technology
Happy Translating! ๐