How styayur/translation-kernel works
Translation Kernel is a browser translation engine exposed through a Chromium extension and reusable TypeScript APIs. The main user flow is request translation from the extension, scan and segment page text, route bounded batches to configured providers, then render reversible translations; restore stops work and removes rendered text. The map also preserves configuration, site rules, actions, adapters, events, SDK, and provider integrations. Several extension and example internals were not excerpted, so documented links are cited to the README rather than treated as inspected calls.
Main entry points: src/index.ts Translation kernel · background.ts Extension worker · src/index.ts HTML discovery · src/index.ts Public SDK
Components 22
Browser extension
- Popup controls
apps/browser-extension/src/popup.ts - Extension worker
apps/browser-extension/src/background.ts - Page content script
apps/browser-extension/src/content.ts - Settings UI
apps/browser-extension/src/options.ts
Translation runtime
- Translation kernel
packages/core/src/index.ts - HTML discovery
packages/dom/src/index.ts - Text segmenter
packages/segmenter/src/index.ts - Reversible renderer
packages/renderer/src/index.ts - Translation cache
packages/core/src/cache.ts - Provider router
packages/provider-api/src/index.ts
Integration APIs
- Document model
packages/shared/src/index.ts - Document adapter API
packages/adapter-api/src/index.ts - Event API
packages/event-api/src/index.ts - Action API
packages/action-api/src/index.ts - Public SDK
packages/sdk/src/index.ts
Configuration
- Site rules
packages/rules/src/index.ts - Config validation
packages/config/src/index.ts
Example integrations
- Provider examples
examples/providers/src/index.ts - Action examples
examples/actions/src/index.ts - Adapter examples
examples/adapters/src/index.ts - Bridge examples
examples/bridges/src/index.ts
Other components
- Page user
Connections 26
- Page user → Popup controls: requests translation
README.md - Popup controls → Extension worker: sends controls
- Settings UI → Extension worker: manages settings
- Extension worker → Page content script: injects script
apps/browser-extension/src/background.ts - Page content script → Translation kernel: starts translation
README.md - Page content script → HTML discovery: uses HTML adapter
apps/browser-extension/src/content.ts - Extension worker → Config validation: validates settings
apps/browser-extension/src/background.ts - Extension worker → Provider router: routes batches
apps/browser-extension/src/background.ts - Extension worker → Provider examples: registers providers
apps/browser-extension/src/background.ts - Translation kernel → HTML discovery: reads and renders
packages/core/src/index.ts - Translation kernel → Provider router: requests batches
packages/core/src/index.ts - Translation kernel → Translation cache: reads and writes
packages/core/src/index.ts - Translation kernel → Event API: emits lifecycle
packages/core/src/index.ts - Translation kernel → Document model: segments documents
packages/core/src/index.ts - HTML discovery → Text segmenter: segments text
packages/dom/src/index.ts - HTML discovery → Site rules: resolves exclusions
packages/dom/src/index.ts - HTML discovery → Reversible renderer: renders and restores
packages/dom/src/index.ts - Provider router → Provider examples: calls provider
- Config validation → Action API: validates action URLs
packages/config/src/index.ts - Public SDK → Translation kernel: exports API
packages/sdk/src/index.ts - Public SDK → Document adapter API: exports contract
packages/sdk/src/index.ts - Public SDK → Event API: exports events
packages/sdk/src/index.ts - Public SDK → Action API: exports actions
packages/sdk/src/index.ts - Adapter examples → Document adapter API: implements contract
- Action examples → Action API: provides actions
- Bridge examples → Document adapter API: bridges documents