# TranslateWorker

**Kind:** Class

**Source:** [`atloria-monorepo/apps/api/src/l10n/translate.worker.ts`](https://github.com/sherkety/atloria/blob/main/atloria-monorepo/apps/api/src/l10n/translate.worker.ts#L29)

TranslateWorker — consumer of the 'l10n-translate' queue (B6).

One job = one (document, targetLanguage) variant: build the directive-preserving prompt
(with the project glossary), call the doc-automation AI provider (AZURE_GPT52_PROVIDER —
the same gpt-5.6-terra deployment the generation pipeline uses), then ENFORCE the contract:
the result only auto-publishes when every protected segment (directives, code fences)
survived verbatim. A violating result is saved as a DRAFT for human review — a broken page
must never reach readers on the say-so of a model.

Kill-switch: L10N_TRANSLATE_WORKER === 'false' disables processing (enqueue-only pods).
Default ON — translate jobs are independent per variant and idempotent (upsert), so
concurrent processing across api replicas is safe.

**Implements:** `OnModuleInit`, `OnModuleDestroy`

## Methods

| Method | Signature | Returns |
|---|---|---|
| `onModuleInit` | `onModuleInit()` | `void` |
| `process` | `process(job: Job<TranslateJob> | { data: TranslateJob })` | `Promise<{
    outcome: 'published' | 'draft-needs-review' | 'skipped';
    reason?: string;
  }>` |
| `onModuleDestroy` | `onModuleDestroy()` | `Promise<void>` |

## Where it refuses work

- `TranslateWorker` stops the work with `Error` when `!this.aiProvider` — “AI provider unavailable (AZURE_GPT52_PROVIDER not configured)”.
- `TranslateWorker` stops the work with `Error` when `!parsed.content.trim()` — “model returned empty translation”.
- `TranslateWorker` stops the work with an early return when `!pair.source.content?.trim()`.
- `TranslateWorker` stops the work with an early return when `pair.source.language === language`.
- `TranslateWorker` stops the work with an early return when `pair.variant && !pair.variant.machineTranslated`.

## Referenced By

- `L10nModule` (MODULE_PROVIDES)
