Introducing a new way to review your PRs.

Read the announcement

generaltranslation / gt

Full-stack localization for every framework

View on GitHub

22 documents · Updated Nov 23, 2026

docs / session-recording-localization

Session recording localization

The /home/user/repo/packages/rrweb package records a product walkthrough once and presents the same session in the app's published locales. It combines an rrweb event stream with a per-locale text overlay, so a viewer can see the recorded source flow or switch its visible text without a new recording or an online translation step. This page complements Translation operations and links to Translation API client, GTX command-line workflows, Locadex operations, Sanity CMS integration, Payload CMS integration, and Bundle analysis for related translation systems.

Product model

Recording bundle

The recording bundle is the handoff between capture, translation lookup, and replay. It contains the rrweb event stream, an ordered locale list, and text replacements keyed by rrweb node ID; the first locale is always the source render.

PartPurpose
eventsReconstructs the page, user actions, and visited session state.
localesNames the source and target locales in source-first order.
overlayMaps each target locale to the text that can replace recorded source nodes.

The bundle can also travel as an events-only export. The recorder writes locale and overlay data into rrweb custom events, so the replay can recover localization metadata when the structured bundle fields are not present.

References: packages/…/types.ts• L1-19 packages/…/types.ts• L77-86 packages/…/player.ts• L8-19 packages/…/player.ts• L1531-1567

Translation overlay

The overlay reads the app's own published translations and places them on the matching recorded text nodes. It does not translate text or render each locale again. This lets the replay preserve interaction-only states and the exact session path while changing only text that has a safe match.

Structured <T> content matches through a message hash carried by the recorded DOM. Bare gt() and useGT() strings can use an optional message hash function. Variables keep their recorded values, and the source text remains visible when a translation is missing or its structure does not match the recording.

References: packages/…/harvest.ts• L10-23 packages/…/harvest.ts• L41-48 packages/…/harvest.ts• L274-333 packages/…/harvest.ts• L336-373

Capture flow

Recorder lifecycle

The recorder owns one in-memory session at a time. A caller supplies the locales in source-first order, the recorder captures the browser activity, and stopping the session harvests target overlays before it returns the completed bundle.

The lifecycle has three visible states:

  • idle: no capture is active.
  • preparing: the recorder is preparing capture or harvesting translations.
  • recording: rrweb is collecting the session.

The capture state lives outside the React component that displays the controls. This allows route changes and component remounts to leave the same recording active. A stop during preparation cancels the pending session; an abort discards it without harvesting.

References: packages/…/types.ts• L18-19 packages/…/recorderCore.ts• L23-57 packages/…/recorderCore.ts• L188-250 packages/…/recorderCore.ts• L253-331

Capture boundary

The recorder captures the content region and the user actions needed to replay a walkthrough. It can preserve a chosen capture shape, record single-page-app navigation as session data, and keep the replay self-contained across origins by preparing the page's font assets before capture.

Privacy and signal choices shape this boundary:

  • Input values are masked so typed secrets and personal data are not recorded.
  • High-volume mouse movement is omitted; the replay creates a readable cursor path from click points.
  • Scroll activity remains available to the rrweb stream.
  • The capture overlay is excluded from the replay while its stop control remains available to the operator.

References: packages/…/recorderCore.ts• L81-164 packages/…/recorderCore.ts• L212-248 packages/…/RecordingOverlay.tsx• L6-13 packages/…/inlineFonts.ts• L1-11

Capture and harvest sequence

The sequence below shows how a source session becomes a localized replay bundle.

flowchart LR
    A[Start with source-first locales] --> B[Prepare fonts and capture frame]
    B --> C[Record DOM and user activity with rrweb]
    C --> D[Stop and collect event stream]
    D --> E[Load published target translations]
    E --> F[Match message hashes to recorded nodes]
    F --> G[Embed locale metadata and overlay]
    G --> H[Return replay bundle]

Harvest runs in the browser after capture stops. It loads each target locale separately, skips the source locale, and treats a failed locale load as an empty overlay rather than failing the whole recording. If no translation loader is supplied, the bundle remains source-only.

References: packages/…/harvest.ts• L391-418 packages/…/recorderCore.ts• L253-309

Replay flow

Localized presentation

The replayer reconstructs the recorded page inside a self-contained player, then applies the selected locale's overlay to the live replay document. The source locale shows the recorded text. A target locale changes matching text in place, so page structure, images, and the recorded interaction sequence stay unchanged.

The viewer can choose an initial locale and can show or hide the locale switcher. When switching is allowed, the player restores changed nodes to source before applying the next overlay. It also checks that a live node still contains its recorded source value, which prevents a stale translation from replacing a later dynamic value.

References: packages/…/player.ts• L643-736 packages/…/player.ts• L1359-1412 packages/…/GTReplayer.tsx• L9-40

Playback experience

The player presents the recording as an interactive walkthrough rather than as a raw event dump. It starts after the replay styles are ready, uses a readable cursor and click signal, supports play and pause, and provides a time scrubber. Backward scrubbing uses a separate hidden replay state and copies only the changed page parts into the visible view, which keeps localization and page styling stable while the viewer seeks.

The player also supports a light or dark view, full-screen mode, and an optional debug drop zone for replacing the current replay with a valid recording JSON file. These controls affect presentation only; they do not change the recorded session or its translation data.

References: packages/…/player.ts• L360-457 packages/…/player.ts• L784-851 packages/…/player.ts• L1119-1282 packages/…/player.ts• L1580-1649

Replay interfaces

The package exposes React components for common app use and a lower-level factory for hosts that need direct lifecycle control. It publishes a main entry point plus focused harvest and replay entry points, so a host can use the full surface or one lifecycle boundary.

InterfaceRole
GTRecorderConnects recording configuration and the visible recording controls.
useRecorderStarts and stops capture from any React tree location while exposing recorder status.
GTReplayerMounts and destroys a player through React lifecycle.
createGTReplayerMounts a player into an existing element and returns a destroy handle.
harvestLocalesBuilds locale overlays from an rrweb event stream and translation loader.

The recorder and replayer are client-side interfaces. The recording component is disabled until enabled, while the replayer expects a parent with usable size and reports invalid or too-short recordings inside the player. The public entry-point contract is checked for both recorder and replayer exports.

References: packages/…/index.ts• L1-20 packages/…/replay.ts• L1-10 packages/…/GTRecorder.tsx• L16-83 packages/…/useRecorder.ts• L16-43 packages/…/player.ts• L21-45 packages/…/player.ts• L1596-1649 packages/…/packageExports.test.ts• L9-24 packages/…/package.json• L66-96

Configuration types

Configuration types define the contract between an app and capture. RecorderConfig names the locales traced by a session. HarvestOptions supplies the app's translation loader and can identify the source locale through an explicit value or a named locale cookie. FrameOption controls whether the capture uses its natural size or a fixed aspect ratio.

The app must keep the source locale first unless it supplies sourceLocale. The loader returns the app's published translation dictionary, so the rrweb package does not need to know which translation service or framework produced it.

References: packages/…/types.ts• L6-9 packages/…/types.ts• L21-36 packages/…/types.ts• L39-74

Replay types

Replay types describe a recording that may include either structured localization fields or only the rrweb event stream. GTReplayerOptions selects the initial locale, controls locale switching, and enables optional debug replacement. The returned handle gives the host one required lifecycle action: destroy the player when the host no longer needs it.

This separation lets stored recordings remain useful as raw rrweb data while still supporting localized playback when the recorder's embedded custom events are available.

References: packages/…/player.ts• L8-45 packages/…/player.ts• L1517-1567

Change checklist

When these files or sections are changed, remember to consider these:

  • Changes to RecorderBundle, GTReplayerBundle, or GT_EVENT must stay compatible with both structured bundle consumers and events-only recordings that recover metadata from custom events.
  • Changes to message-hash or translation-dictionary shape must preserve alignment between recorded text-node IDs and translated leaves. A mismatch must still fall back to source rather than apply text to the wrong node.
  • Changes to source-locale selection must keep RecorderConfig.locales[0], HarvestOptions.sourceLocale, the locale cookie path, and the replay's source button consistent.
  • Changes to capture framing or embedded fonts must be checked against replay cropping and cross-origin font loading. The recorded frame and its assets define the visual bounds of the player.
  • Changes to masked input capture or the recording overlay must preserve the privacy boundary between operator controls and replayed content.

Important failure modes

TriggerConsequenceGuard
No loadTranslations function is suppliedThe recording replays in the source locale even when target locales are listed.Pass the app's published-translation loader through HarvestOptions.
A target loader fails or returns no usable dictionaryThat target receives an empty overlay and falls back to source text; other targets can still work.Treat the target as source-only and check loader availability before capture.
The translation leaf count differs from the recorded text-node countThe affected message is not localized, which avoids assigning text to the wrong node.Keep translation structure and recorded message structure aligned.
gt() or useGT() text is harvested without hashMessageBare strings have no DOM hash and remain on source; structured <T> content can still be harvested.Provide the same message hash function used by the app.
The source locale is not first and no explicit source locale is setHarvest may treat the wrong locale as source and skip its overlay.Keep locale lists source-first or set sourceLocale.
The event stream has fewer than two events or no usable snapshotThe player shows an in-player recording error instead of starting playback.Pass a completed rrweb recording bundle.
A recording is stopped while font preparation is pendingNo recording starts and no bundle is returned.Wait for status === 'recording' before treating stop as completion.

Key files

FileWhy to read it
packages/…/types.tsDefines the bundle, locale, harvest, recorder-state, and capture-frame contracts.
packages/…/harvest.tsExplains how published translations become safe node-level overlays.
packages/…/recorderCore.tsShows the capture, stop, navigation, metadata, and harvest lifecycle.
packages/…/GTRecorder.tsxShows the app-facing recording component and configuration boundary.
packages/…/useRecorder.tsShows how React callers control the shared recorder state.
packages/…/player.tsShows localized replay, playback controls, seeking, and embedded metadata recovery.
packages/…/GTReplayer.tsxShows the React mount and teardown boundary for replay.
packages/…/inlineFonts.tsExplains why capture prepares font assets for portable replay.
packages/…/package.jsonShows the package's public entry points and peer runtime boundary.
packages/…/README.mdGives the package's short product statement and current package status.