Skip to content

mountlord/gTranslate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auto Page Translator

A Chrome extension for automatic page translation with a focus on Korean websites that don't properly set language attributes (preventing Chrome's built-in translator from working).

Features

  • One-Click Translation: Click the extension icon and translate any page instantly
  • Auto-Translate by Domain: Configure domains (like .kr) to translate automatically on page load
  • Visual Status Indicators: Icon changes color to show translation state
    • Gray: Neutral/English page
    • Red: Foreign language detected, needs translation
    • Green: Page has been translated
  • Dynamic Content Support: Automatically translates new content as it appears (chat messages, live updates, etc.)
  • Smart Batching: Translates efficiently by batching requests and deduplicating repeated text
  • In-Memory Cache: Previously translated text is instant on repeat encounters

Installation

  1. Download or clone this repository
  2. Open Chrome and navigate to chrome://extensions/
  3. Enable "Developer mode" (toggle in top right)
  4. Click "Load unpacked" and select the extension folder
  5. The translator icon will appear in your toolbar

Usage

Manual Translation

  1. Navigate to any webpage
  2. Click the extension icon in your toolbar
  3. Select source and target languages (defaults: Korean → English)
  4. Click "Translate Page"

Auto-Translation Setup

  1. Click the extension icon
  2. Check "Auto-translate on these domains"
  3. Enter domain patterns (comma-separated):
    • .kr - matches all Korean domains
    • sooplive.co.kr - matches specific site and subdomains
    • example.com - exact domain match
  4. Click "Save Settings"

Technical Details

Performance Optimizations (v2.0)

This version includes major performance improvements:

Optimization Impact
Batch Translation Reduces network requests by 20-50x using glue-string batching
Deduplication Translates each unique string only once, even if it appears 100+ times
In-Memory Cache Instant translation for previously seen text
Concurrent Requests 4 parallel batch requests with automatic rate-limit handling
Language Heuristics Skips pure ASCII/numbers/punctuation (no wasted API calls)
MutationObserver Automatically catches and translates dynamic content

Translation Pipeline

  1. Collect all text nodes from the page
  2. Skip nodes that don't need translation (English, numbers, already processed)
  3. Deduplicate: group nodes by their text content
  4. Check in-memory cache for previously translated strings
  5. Batch remaining texts into groups (max 40 items or 4000 chars per batch)
  6. Send batches concurrently (max 4 at a time) with retry/backoff
  7. Update cache with results
  8. Apply translations to all nodes
  9. Start MutationObserver to catch dynamic content

Translation Backend

Currently uses:

  • Primary: Google Translate (unofficial translate.googleapis.com endpoint)
  • Fallback: MyMemory Translation API

The backend is abstracted for future support of:

  • Google Cloud Translation API (with user API key)
  • DeepL API
  • Local translation servers (LibreTranslate, Opus-MT)

Configuration Constants

Located at the top of content.js:

const CONFIG = {
  BATCH_MAX_CHARS: 4000,      // Max characters per batch request
  BATCH_MAX_ITEMS: 40,        // Max items per batch
  CONCURRENT_REQUESTS: 4,     // Parallel request limit
  MUTATION_DEBOUNCE_MS: 300,  // Debounce time for dynamic content
  RETRY_ATTEMPTS: 3,
  RETRY_BASE_DELAY_MS: 250,
};

File Structure

gTranslate/
├── manifest.json      # Extension configuration
├── background.js      # Service worker (auto-translate trigger, icon management)
├── content.js         # Main translation logic (runs on web pages)
├── popup.html         # Extension popup UI
├── popup.css          # Popup styling
├── popup.js           # Popup interaction logic
├── icons/             # Extension icons (gray/red/green states)
└── README.md          # This file

Supported Languages

  • Korean (ko) - Primary target
  • Japanese (ja)
  • Chinese Simplified (zh-CN)
  • Chinese Traditional (zh-TW)
  • Spanish (es)
  • French (fr)
  • German (de)
  • Russian (ru)
  • Auto-detect (auto)

Target languages:

  • English (en) - Default
  • All source languages also available as targets

Known Limitations

  • Unofficial API: The Google Translate endpoint used is unofficial and may have rate limits or occasional failures. The extension handles this with retry logic and MyMemory fallback.
  • iframes: Content inside iframes is not currently translated (can be enabled in manifest.json with all_frames: true)
  • Shadow DOM: Web components using Shadow DOM are not translated

Troubleshooting

Translation is slow

  • Check your network connection
  • The first translation builds the cache; subsequent translations will be faster
  • Very large pages (10,000+ text nodes) will take longer

Some text isn't translated

  • Text inside iframes won't be translated
  • Pure English/ASCII text is intentionally skipped
  • Some dynamically loaded content may take a moment to be caught by MutationObserver

"Translation failed" error

  • May indicate rate limiting - wait a few seconds and try again
  • Check the browser console (F12) for detailed error messages

Development

Console Logging

The extension logs detailed information to the browser console:

  • [Translator] - Content script messages
  • [Translator BG] - Background script messages

Debugging

  1. Open the page you want to translate
  2. Open DevTools (F12)
  3. Check Console for translation logs
  4. Look for stats like:
    [Translator] Found 1500 text nodes
    [Translator] 200 unique texts (800 skipped)
    [Translator] Cache: 50 hits, 150 misses
    [Translator] Created 4 batches
    [Translator] Done: 700 nodes translated in 2340ms
    

License

AGPL-3.0

Repository

https://github.com/mountlord/gTranslate.git

About

A powerful Chrome/Chromium browser extension that automatically translates web pages with customizable language settings and domain-based auto-translation.

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors