* feat: workflow auto translation * tests: add unit tests * refactor: tests and workflow * fix: type err * fix: type err * fix: remove redundant index on WorkflowStepTranslation The @@index on [workflowStepId, field, targetLocale] duplicates the @@unique constraint on the same columns. A unique index already provides efficient lookups, so the separate @@index adds storage overhead and write latency without benefit. Addresses Cubic AI review feedback (confidence 9/10). Co-Authored-By: unknown <> * fix: correct locale mapping when translation API returns null Map translations with their corresponding locales before filtering to preserve correct locale-to-translation associations. Previously, filtering out null translations would reindex the array, causing incorrect locale mappings when any translation in the batch failed. Also fixes pre-existing lint warnings: - Move exports to end of file - Add explicit return type to processTranslations - Replace ternary with if-else for upsertMany selection Co-Authored-By: udit@cal.com <udit222001@gmail.com> * fix: address review feedback for workflow auto-translation - Add change detection before creating translation tasks - Rename userLocale to sourceLocale in task props for clarity - Show source language in UI with new translation key - Extract SUPPORTED_LOCALES to shared translationConstants.ts - Fix locale mapping bug in translateEventTypeData.ts - Add WhatsApp translation support - Abstract translation lookup into shared translationLookup.ts helper - Restore if-else readability for SCANNING_WORKFLOW_STEPS Co-authored-by: Udit Takkar <udit.takkar@cal.com> Co-Authored-By: unknown <> * fix: update test to use sourceLocale instead of userLocale Co-Authored-By: unknown <> * refactor: feedback * fix: handle first time * fix: tests * fix: tests * fix: address Cubic AI review feedback (confidence 9/10 issues) - WhatsApp translation: Apply variable substitution using getSMSMessageWithVariables and clear contentSid when using translated body to ensure Twilio uses the translated text instead of the original template - update.handler.ts: Change sourceLocale assignment from ?? to || for consistency with tasker payload behavior (line 481) - ITranslationService.ts: Rename methods from plural to singular naming: - getWorkflowStepTranslations -> getWorkflowStepTranslation - getEventTypeTranslations -> getEventTypeTranslation Updated all call sites and tests accordingly Co-Authored-By: unknown <> * fix: address Cubic AI review feedback (confidence 9/10+ issues) - Fix getSMSMessageWithVariables to handle WHATSAPP_ATTENDEE action for locale and timezone (confidence 9/10) - Remove WhatsApp translation feature that set contentSid to undefined since Twilio ignores body parameter for WhatsApp and requires pre-approved Message Templates (confidence 10/10) Co-Authored-By: unknown <> * fix: translatio * Add tests: packages/features/eventTypeTranslation/repositories/EventTypeTranslationRepository.test.ts Generated by Paragon from proposal for PR #27087 * Add tests: packages/features/tasker/tasks/translateWorkflowStepData.test.ts Generated by Paragon from proposal for PR #27087 * chore: nit * chore: verfied atg * fix: set sourceLocale for new steps, add shouldDirty to checkbox, remove spec docs - Set sourceLocale fallback in addedSteps mapping to fix stale detection mismatch - Add { shouldDirty: true } to autoTranslateEnabled checkbox onChange - Remove specs/workflow-translation/ directory (planning docs, not for repo) Co-authored-by: Udit Takkar <udit.07.takkar@gmail.com> Co-Authored-By: unknown <> * chore: add specs back * fix: type error * fix: type error * fix: type err * fix: tests * refactor: feedback * fix: type err * refactor --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Udit Takkar <udit.takkar@cal.com> Co-authored-by: Udit Takkar <udit.07.takkar@gmail.com>
3.3 KiB
Workflow Translation Design
Overview
Translate workflow reminderBody and emailSubject to the visitor's browser language using lingo.dev. Follows the existing pattern for event type title/description translation.
Problem Statement
Workflow notifications are sent in the language they were written, not the attendee's language. Organizations need attendees to receive notifications in their preferred language.
User Stories
- As an org admin, I want workflow notifications translated to the attendee's language so international attendees understand the message
- As an attendee, I want to receive booking notifications in my browser language
Technical Design
Database Changes
Add to schema.prisma:
enum WorkflowStepAutoTranslatedField {
REMINDER_BODY
EMAIL_SUBJECT
}
model WorkflowStepTranslation {
uid String @id @default(cuid())
workflowStep WorkflowStep @relation(fields: [workflowStepId], references: [id], onDelete: Cascade)
workflowStepId Int
field WorkflowStepAutoTranslatedField
sourceLocale String
targetLocale String
translatedText String @db.Text
sourceHash String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([workflowStepId, field, targetLocale])
@@index([workflowStepId, field, targetLocale])
}
Add to WorkflowStep:
autoTranslateEnabled: Boolean @default(false)sourceLocale: String?translations: WorkflowStepTranslation[]
API Changes
Workflow update handler (packages/trpc/server/routers/viewer/workflows/update.handler.ts):
- Accept
autoTranslateEnabledandsourceLocalefields - Trigger
translateWorkflowStepDatatasker task when content changes
New tasker task (packages/features/tasker/tasks/translateWorkflowStepData.ts):
- Uses
TranslationServiceto translate body/subject to 19 target locales - Store translations in
WorkflowStepTranslationtable via repository
TranslationService
Shared service at packages/features/translation/services/TranslationService.ts:
translateText()- Translates text to all supported locales using LingoDotDevServicegetWorkflowStepTranslations()- Looks up cached translations for workflow stepsgetEventTypeTranslations()- Looks up cached translations for event types- Uses DI pattern with repositories injected via constructor
Send-Time Integration
EmailWorkflowService (generateEmailPayloadForEvtWorkflow):
- Uses
TranslationService.getWorkflowStepTranslations()to lookup translation - Fallback to original text if no translation found
smsReminderManager / whatsappReminderManager:
- Same pattern: uses TranslationService for attendee locale lookup
UI Changes
WorkflowStepContainer.tsx:
- Add "Auto-translate for attendees" toggle
- Only show for org users and attendee-targeted actions
Supported Locales
19 locales (same as event types): en, es, de, pt, pt-BR, fr, it, ar, ru, zh-CN, zh-TW, ko, ja, nl, sv, da, is, lt, nb
Scope
Supported actions: EMAIL_ATTENDEE, SMS_ATTENDEE, WHATSAPP_ATTENDEE
Not supported: EMAIL_HOST, EMAIL_ADDRESS, SMS_NUMBER (no attendee locale available)
Out of Scope
- Form-based workflows (FORM_SUBMITTED triggers)
- CAL_AI_PHONE_CALL action
- Translation of default templates (already use i18n)