Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

PolyGlot - Live AI-Powered Translator

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.

License Version Node

โœจ Features

  • ๐ŸŒ 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

๐Ÿ›  Technology Stack

  • 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

๐Ÿ“ Project Structure

/
โ”œโ”€โ”€ 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 
  1. Install dependencies

    npm install
  2. Start the development server

    npm start
  3. Open your browser Navigate to http://localhost:3000

  4. Configure your API key

    • Enter your OpenAI API key in the settings panel
    • The key is stored securely in localStorage

Available Scripts

  • npm start - Start development server
  • npm run dev - Start with auto-reload (no cache)
  • npm run lint - Check code quality
  • npm run lint:fix - Fix linting issues automatically
  • npm run format - Format code with Prettier
  • npm run validate - Run linting and format checks
  • npm run build - Validate and build for production

๐ŸŒŸ Usage

Basic Translation

  1. Enter your OpenAI API key in the settings panel
  2. Type or paste text in the source language box
  3. Select source and target languages
  4. Click "Translate" or enable live translation

Voice Features

  • ๐ŸŽค 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

Keyboard Shortcuts

  • Ctrl/Cmd + Enter - Translate text
  • Ctrl/Cmd + K - Clear all text
  • Ctrl/Cmd + M - Toggle voice input

๐Ÿ— Architecture

Modular JavaScript Design

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

๐Ÿ”ง Configuration

Environment Variables

The app uses localStorage for configuration. No server-side environment variables needed.

Adding Languages

Update the language maps in TranslationEngine.js:

this.languageNames = {
  'auto': 'Auto Detect',
  'en': 'English',
  'es': 'Spanish', // Add new language
  // ... more languages
};

Required Browser APIs

  • Fetch API
  • ES6 Modules
  • CSS Custom Properties
  • Web Speech API (optional, for voice features)

๐Ÿš€ Performance 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

๐Ÿ”’ Security & Privacy

  • 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

๐Ÿงช Development

Code Quality

  • ESLint - Code linting with recommended rules
  • Prettier - Consistent code formatting
  • JSDoc - Comprehensive code documentation
  • Error Boundaries - Robust error handling

Testing the Application

  1. Test with different languages and text lengths
  2. Verify voice recognition works in supported browsers
  3. Test responsive design on various screen sizes
  4. Validate offline functionality with service worker

๐Ÿค Contributing

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

Development Guidelines

  • Follow the existing code style
  • Add JSDoc comments for new functions
  • Update tests for new features
  • Ensure responsive design compatibility

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

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

image

๐ŸŒŸ Features

Core Translation Features

  • 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

Advanced Features

  • 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

๐Ÿš€ Quick Start

Prerequisites

  • Modern web browser with JavaScript enabled
  • OpenAI API key (Get one here)
  • Internet connection for API calls

Setup Instructions

  1. Clone or Download

    git clone https://github.com/yourusername/polyglot-translator.git
    cd polyglot-translator
  2. Open the Application

    • Open index.html in 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
  3. 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
  4. 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

๐ŸŽฎ How to Use

Basic Translation

  1. Enter text in the left text area
  2. Select source and target languages
  3. Click the "Translate" button
  4. View the translation in the right text area

Voice Input

  1. Click the microphone button (๐ŸŽค)
  2. Speak clearly in your chosen language
  3. The speech will be converted to text automatically
  4. Translation happens instantly if live mode is enabled

Live Translation

  1. Toggle the "Live Translation" switch
  2. Start typing in the source text area
  3. Translation updates automatically after 1 second pause
  4. Perfect for real-time conversations

Text-to-Speech

  1. Click the play button (โ–ถ๏ธ) next to any text area
  2. Listen to the pronunciation in the selected language
  3. Supports all target languages with native voice synthesis

โŒจ๏ธ Keyboard Shortcuts

  • Ctrl/Cmd + Enter: Translate text
  • Ctrl/Cmd + K: Clear all text
  • Ctrl/Cmd + M: Toggle voice input
  • Tab: Navigate between elements
  • Enter: Save API key (when focused on key input)

๐ŸŒ Supported Languages

Language Code Voice Input Text-to-Speech
English en โœ… โœ…
Vietnamese vi โœ… โœ…
Japanese ja โœ… โœ…
German de โœ… โœ…
Chinese zh โœ… โœ…

๐Ÿ”ง Configuration

OpenAI API Setup

  1. Visit OpenAI Platform
  2. Create an account or sign in
  3. Generate a new API key
  4. Copy the key and paste it in PolyGlot's settings
  5. Ensure you have sufficient API credits

Browser Permissions

  • Microphone Access: Required for voice input
  • Local Storage: Used to save API key and history
  • Clipboard Access: For copy translation feature

๐Ÿ“ฑ Mobile Support

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

๐Ÿ”’ Privacy & Security

  • 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

๐Ÿ› ๏ธ Customization

Adding New Languages

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.

Styling Customization

Modify styles.css to customize:

  • Color scheme (change CSS custom properties)
  • Layout and spacing
  • Animations and transitions
  • Mobile breakpoints

๐Ÿ› Troubleshooting

Common Issues

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

Browser Compatibility

Feature Chrome Firefox Safari Edge
Basic Translation โœ… โœ… โœ… โœ…
Voice Input โœ… โŒ โœ… โœ…
Text-to-Speech โœ… โœ… โœ… โœ…
Live Translation โœ… โœ… โœ… โœ…

๐Ÿ“ API Usage

OpenAI Model Used

  • Model: GPT-3.5-turbo
  • Max Tokens: 1000 per translation
  • Temperature: 0.3 (for consistent translations)

Cost Estimation

  • Average cost: ~$0.002 per translation
  • 1000 translations โ‰ˆ $2.00
  • Voice input adds no extra cost

๐Ÿค Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

Development Setup

  1. Clone the repository
  2. Make changes to HTML, CSS, or JavaScript files
  3. Test in multiple browsers
  4. Ensure mobile compatibility

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • 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

๐Ÿ“ž Support

๐Ÿ”„ Version History

v1.0.0 (Current)

  • Initial release with full translation features
  • Voice input and text-to-speech support
  • Live translation mode
  • Multi-language support
  • Responsive design
  • Translation history

Planned Features

  • 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! ๐ŸŒ

Releases

Packages

Contributors

Languages