diff --git a/backend/app/api/v1/routes_jobs.py b/backend/app/api/v1/routes_jobs.py index 55df8b5..b6ca2a1 100644 --- a/backend/app/api/v1/routes_jobs.py +++ b/backend/app/api/v1/routes_jobs.py @@ -873,9 +873,22 @@ async def approve_source( detail="Job not in pending QC status" ) - # Transition directly to PENDING_FINAL_REVIEW - # Translation, TTS, and accessible video rendering now happen BEFORE QC - new_status = JobStatus.PENDING_FINAL_REVIEW + # Determine if there are target languages that still need translation. + source_language = job_doc["source"].get("language", "en") + requested_langs = job_doc.get("requested_outputs", {}).get("languages", []) + target_languages = [lg for lg in requested_langs if lg != source_language] + existing_outputs = job_doc.get("outputs") or {} + untranslated = [ + lg for lg in target_languages + if not (existing_outputs.get(lg) or {}).get("captions_vtt_gcs") + ] + + # If untranslated target languages exist, dispatch translation instead of + # jumping straight to final review. Any role can trigger this. + if untranslated: + new_status = JobStatus.TRANSLATING + else: + new_status = JobStatus.PENDING_FINAL_REVIEW # Build update operations update_set = { @@ -917,8 +930,11 @@ async def approve_source( detail="Job not found or not in pending QC status" ) - # No need to trigger translate_and_synthesize_task - all processing done before QC - logger.info(f"Job {job_id} approved, transitioning directly to final review") + if untranslated: + await _cr_dispatch("translate", job_doc["_id"], languages=untranslated) + logger.info(f"Job {job_id} source approved — dispatching translation for {untranslated}") + else: + logger.info(f"Job {job_id} approved, transitioning directly to final review") await log_job_action( AuditAction.JOB_APPROVE, job_id, current_user, http_request,