Skip to content

feat(translator): auto-translate on source-locale content change (#51)#76

Open
SearheiParkhamchuk wants to merge 3 commits into
mainfrom
feat/translator-auto-translate-on-source-change
Open

feat(translator): auto-translate on source-locale content change (#51)#76
SearheiParkhamchuk wants to merge 3 commits into
mainfrom
feat/translator-auto-translate-on-source-change

Conversation

@SearheiParkhamchuk

Copy link
Copy Markdown
Contributor

Summary

Opt-in, per-collection auto-translation that queues translations for configured target locales whenever a document's source-locale content changes. Off by default; configured by the developer in code.

Closes #51. Public API @since 0.9.0 (feat → minor).

How it works

Wrap a collection with withAutoTranslate(collection, { targets, ... }). The plugin injects a best-effort afterChange hook that:

  1. Drift gatehasSourceContentChanged (source fingerprint) skips saves that didn't change source content.
  2. Publish-only trigger — fires only when the source is published; autosave/draft saves are ignored (no-drafts collections: every save counts).
  3. Enqueues the configured targets through the existing pipeline; auto-translated target status mirrors the source.

Design decisions

  • Config source of truth on collection.custom via withAutoTranslate (mirrors withFieldTranslation); payload-free reader getAutoTranslateConfig.
  • Debounce via optional TaskInput.waitUntil + existing pending-job supersession — a fresh edit cancels and replaces the delayed job.
  • Loop guard: source-locale check + a transient req.context flag set by the translate handler's write-back.
  • Future manager layer: AutoTranslatePolicyResolver(slug, doc) seam reserved (v1 ignores doc).
  • Best-effort: the hook never fails the editor's save.

Serverless / Vercel caveat

Auto-translate only enqueues; execution depends on the job runner's autorun. On serverless (e.g. Vercel) where cron-based autorun may not run, enqueued translations can sit unexecuted until triggered externally. Documented on the withAutoTranslate JSDoc + README.

Testing

  • check-types
  • test ✓ (1079 tests, incl. new units for policy, enqueue hook, config reader, hasSourceContentChanged, plugin wiring, both task runners)
  • lint ✓ (no new warnings vs. main baseline)

Design doc: docs/plans/2026-07-15-auto-translate-on-source-change-51.md.

Opt-in, per-collection auto-translation. Wrap a collection with
`withAutoTranslate(collection, opts)` and the plugin queues translations
for the configured target locales whenever source-locale content changes.
Off by default; configured by the developer in code.

- Config source of truth on `collection.custom` via `withAutoTranslate`
  (mirrors `withFieldTranslation`); payload-free reader `getAutoTranslateConfig`.
- Drift gate `hasSourceContentChanged` (source fingerprint) skips unchanged saves.
- Debounce via optional `TaskInput.waitUntil` + existing pending-job supersession.
- Loop guard: source-locale check + a transient `req.context` flag set by the
  translate handler's write-back.
- Publish-only trigger; auto-translated target status mirrors the source.
- `AutoTranslatePolicyResolver(slug, doc)` seam reserved for a future
  document-level manager layer (`doc` ignored in v1).
- Best-effort hook (never fails the editor's save). Public API `@since 0.9.0`;
  README documents the serverless/Vercel autorun caveat.
@vercel

vercel Bot commented Jul 17, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
turbo-cms-kit-payload Ready Ready Preview, Comment Jul 17, 2026 3:49pm

Request Review

… popups

Mark collections opted into auto-translate with a quiet lightning-bolt marker in the
header of both translation popups (document + collection); the source locale, target
locales, and the publish trigger are in its tooltip. Ambient config, kept out of the
popup's main flow.

The opt-in is propagated onto the registered collection's `custom` at init, so the UI
reads it reliably even when only the plugin-param object was wrapped with
`withAutoTranslate` (the registered collection can be a different object). Internal
only — no public API change; ships in 0.9.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request translator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[translator] Auto-translate on source content change

1 participant