How ymcwiki/open-immersive-translate works
This is an auditable browser-based bilingual translation product, delivered as a Chromium/Firefox extension and a userscript. The main path scans page text, sends translation requests through the extension background scheduler and configured service adapters, then inserts translated content into the page. Separate workflows cover PDF reading/export, video and subtitle-file translation, assistant features, and configuration. Edges use README statements or SOURCE INDEX references; unsampled subsystem internals and some wiring are therefore represented only where documented.
Main entry points: background/index.ts Background worker · translation-controller.ts Translation controller · scheduler.ts Translation scheduler · services/index.ts Translation adapters
Components 27
Webpage translation
- Content entry
src/content/index.ts - Translation controller
src/content/controller/translation-controller.ts - Text extraction
src/content/extract/scanner.ts - Rich-text placeholders
src/content/extract/placeholder.ts - Page rendering
src/content/render/inject.ts - Userscript runtime
src/userscript/page.ts
Extension runtime
- Background worker
src/background/index.ts - Translation scheduler
src/background/scheduler.ts - Site rules
src/background/rules/match.ts - Translation cache
src/background/cache.ts
Translation services
- Service contract
src/background/services/base.ts - Translation adapters
src/background/services/index.ts - ChatGPT OAuth
src/background/services/chatgpt-oauth/auth.ts - Assistant service
src/background/services/assistant.ts
Other translation experiences
- PDF reader and export
src/pdf/index.tsx - PDF page extraction
src/pdf/page.tsx - Video subtitles
src/content/features/subtitle/engine.ts - Subtitle-file workflow
src/subtitle-file/index.tsx - Assistant side panel
src/ui/sidepanel/index.tsx - AI writing
src/content/features/ai-writing/index.ts - Search enhancement
src/content/features/search-enhancement.ts
Configuration and controls
- Settings page
src/ui/options/index.tsx - Popup controls
src/ui/popup/index.tsx - Shared configuration
src/shared/config.ts
Other components
- Browser user
- Web page
- Translation providers
Connections 28
- Browser user → Web page: opens
README.md - Web page → Content entry: loads script
README.md - Content entry → Translation controller: starts translation
- Translation controller → Text extraction: scans text
src/content/controller/translation-controller.ts - Text extraction → Rich-text placeholders: preserves markup
src/content/extract/scanner.ts - Translation controller → Background worker: requests translation
README.md - Background worker → Site rules: matches site
src/background/index.ts - Background worker → Translation scheduler: dispatches work
src/background/index.ts - Translation scheduler → Translation cache: uses cache
- Translation scheduler → Translation adapters: selects service
- Translation adapters → Service contract: creates services
src/background/services/index.ts - Translation adapters → Translation providers: sends requests
- Translation controller → Page rendering: renders translations
src/content/controller/translation-controller.ts - Settings page → Background worker: configures services
src/ui/options/index.tsx - Popup controls → Background worker: controls translation
README.md - Background worker → Shared configuration: loads settings
src/background/index.ts - Settings page → Site rules: edits site rules
src/ui/options/index.tsx - ChatGPT OAuth → Translation providers: authenticates requests
- Browser user → PDF reader and export: opens PDF
README.md - PDF reader and export → PDF page extraction: renders pages
src/pdf/index.tsx - Browser user → Subtitle-file workflow: imports subtitles
README.md - Browser user → Video subtitles: views video
README.md - Browser user → Assistant side panel: opens panel
README.md - Assistant side panel → Assistant service: requests assistant
- Browser user → AI writing: requests writing help
README.md - Browser user → Search enhancement: uses search
README.md - Browser user → Userscript runtime: installs userscript
README.md - Userscript runtime → Text extraction: scans page text
src/userscript/page.ts