diff --git a/src/components/notes/podcast-panel.test.tsx b/src/components/notes/podcast-panel.test.tsx index f6e7787..6f90a15 100644 --- a/src/components/notes/podcast-panel.test.tsx +++ b/src/components/notes/podcast-panel.test.tsx @@ -49,7 +49,8 @@ describe("PodcastPanel", () => { expect(podcastApi.postPodcastJob).toHaveBeenCalledWith({ source_id: "note-7", format: "tek_ogretici" }); }); expect(sessionStorage.getItem("hezarfen.podcast.note-7")).toBe("j1"); - expect(screen.getByText("Waiting in queue")).toBeTruthy(); + expect(screen.getAllByText("Waiting in queue")).toHaveLength(2); + expect(screen.queryByText("queued")).toBeNull(); }); it("points the audio element at the job's audio door, not the artifact path", async () => { diff --git a/src/components/notes/podcast-panel.tsx b/src/components/notes/podcast-panel.tsx index 904978c..4ada76e 100644 --- a/src/components/notes/podcast-panel.tsx +++ b/src/components/notes/podcast-panel.tsx @@ -233,8 +233,7 @@ export function PodcastPanel(props: { noteId: string; active?: boolean; noteTitl - {/* The stage names itself in the service's own vocabulary and is not - an enumerated set, so the values are shown as they came. */} + {/* Known stage keys are labeled; a stage newer than the map shows as sent. */} 0}> diff --git a/src/components/notes/podcast-stage-trail.test.tsx b/src/components/notes/podcast-stage-trail.test.tsx index a95cad5..5fece5f 100644 --- a/src/components/notes/podcast-stage-trail.test.tsx +++ b/src/components/notes/podcast-stage-trail.test.tsx @@ -1,37 +1,48 @@ import { cleanup, render, screen } from "@solidjs/testing-library"; -import { afterEach, describe, expect, it, vi } from "vitest"; +import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { PodcastStageTrail } from "@/components/notes/podcast-stage-trail"; +import { PreferencesProvider } from "@/stores/preferences-context"; const T = Date.UTC(2026, 0, 2, 10, 0, 0); +function trail(props: { entries: { stage: string; at: number }[]; live: boolean }) { + return ( + + + + ); +} + describe("PodcastStageTrail", () => { + beforeEach(() => { + localStorage.setItem("hezarfen.locale", "en"); + }); + afterEach(() => { cleanup(); + localStorage.removeItem("hezarfen.locale"); vi.useRealTimers(); vi.restoreAllMocks(); }); it("times each stage by the one that replaced it", () => { - render(() => ( - + trail({ + entries: [ { stage: "queued", at: T }, { stage: "synthesizing", at: T + 12_000 }, - ]} - live={false} - label="Aşamalar" - /> - )); + ], + live: false, + }), + ); - expect(screen.getByText("queued")).toBeTruthy(); + expect(screen.getByText("Waiting in queue")).toBeTruthy(); expect(screen.getByText("synthesizing")).toBeTruthy(); expect(screen.getByText("00:12")).toBeTruthy(); }); it("leaves the last stage of a settled job without a span to guess at", () => { - render(() => ( - - )); + render(() => trail({ entries: [{ stage: "queued", at: T }], live: false })); expect(screen.getByText("—")).toBeTruthy(); }); @@ -40,17 +51,13 @@ describe("PodcastStageTrail", () => { vi.useFakeTimers(); vi.setSystemTime(T + 7_000); - render(() => ( - - )); + render(() => trail({ entries: [{ stage: "queued", at: T }], live: true })); expect(screen.getByText("00:07")).toBeTruthy(); }); - it("shows the service's own stage names verbatim", () => { - render(() => ( - - )); + it("shows an unknown stage as the service sent it", () => { + render(() => trail({ entries: [{ stage: "some_unknown_stage", at: T }], live: true })); expect(screen.getByText("some_unknown_stage")).toBeTruthy(); }); diff --git a/src/components/notes/podcast-stage-trail.tsx b/src/components/notes/podcast-stage-trail.tsx index 46d7d44..593bb0f 100644 --- a/src/components/notes/podcast-stage-trail.tsx +++ b/src/components/notes/podcast-stage-trail.tsx @@ -1,6 +1,8 @@ import { For, createSignal, onCleanup } from "solid-js"; import { cn } from "@/lib/cn"; import { formatDurationClock } from "@/lib/format"; +import { podcastStageLabel } from "@/lib/podcast-stage-labels"; +import { useT } from "@/stores/preferences-context"; export type PodcastStageEntry = { /** The service's own stage name, stored as it came. */ @@ -21,6 +23,7 @@ const TICK_MS = 1_000; * inventing the steps before that would be making up a history we never saw. */ export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: boolean; label: string }) { + const t = useT(); const [now, setNow] = createSignal(Date.now()); const timer = window.setInterval(() => setNow(Date.now()), TICK_MS); onCleanup(() => window.clearInterval(timer)); @@ -51,7 +54,7 @@ export function PodcastStageTrail(props: { entries: PodcastStageEntry[]; live: b )} /> - {entry.stage} + {podcastStageLabel(entry.stage, t)} {spanOf(index()) == null ? "—" : formatDurationClock(spanOf(index())!)} diff --git a/src/i18n/locales/en.ts b/src/i18n/locales/en.ts index 5c27f1b..3f6def6 100644 --- a/src/i18n/locales/en.ts +++ b/src/i18n/locales/en.ts @@ -1043,6 +1043,19 @@ export const en: Dict = { "podcast.noNotesHint": "Add a note to one of your courses before creating audio.", "podcast.format": "Narration style", "podcast.stageLabel": "Stages", + "podcast.stage.queued": "Waiting in queue", + "podcast.stage.ocr": "Reading the document", + "podcast.stage.plan": "Planning the episode", + "podcast.stage.kaynak": "Reading the source", + "podcast.stage.metin": "Extracting the text", + "podcast.stage.ingest": "Taking in the source", + "podcast.stage.script": "Writing the script", + "podcast.stage.scriptler": "Writing the script", + "podcast.stage.quiz": "Adding questions", + "podcast.stage.tts": "Narrating", + "podcast.stage.ses": "Narrating", + "podcast.stage.mux": "Mixing", + "podcast.stage.done": "Ready", "podcast.etaHint": "Estimated time: about {secs}s", "podcast.format.duz_okuma": "Straight reading", "podcast.format.tek_ogretici": "Single instructor", diff --git a/src/i18n/locales/tr.ts b/src/i18n/locales/tr.ts index 44aa023..35825d5 100644 --- a/src/i18n/locales/tr.ts +++ b/src/i18n/locales/tr.ts @@ -1039,6 +1039,19 @@ export const tr: Dict = { "podcast.noNotesHint": "Ses oluşturmadan önce derslerinizden birine not ekleyin.", "podcast.format": "Anlatım biçimi", "podcast.stageLabel": "Aşamalar", + "podcast.stage.queued": "Sırada bekliyor", + "podcast.stage.ocr": "Belge okunuyor", + "podcast.stage.plan": "Bölüm planlanıyor", + "podcast.stage.kaynak": "Kaynak okunuyor", + "podcast.stage.metin": "Metin çıkarılıyor", + "podcast.stage.ingest": "Kaynak alınıyor", + "podcast.stage.script": "Metin yazılıyor", + "podcast.stage.scriptler": "Metin yazılıyor", + "podcast.stage.quiz": "Sorular ekleniyor", + "podcast.stage.tts": "Seslendiriliyor", + "podcast.stage.ses": "Seslendiriliyor", + "podcast.stage.mux": "Birleştiriliyor", + "podcast.stage.done": "Hazır", "podcast.etaHint": "Tahmini süre: yaklaşık {secs} sn", "podcast.format.duz_okuma": "Düz okuma", "podcast.format.tek_ogretici": "Tek öğretici", diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index e876885..403fd6a 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -1030,6 +1030,19 @@ export type MessageKey = | "podcast.noNotesHint" | "podcast.format" | "podcast.stageLabel" + | "podcast.stage.queued" + | "podcast.stage.ocr" + | "podcast.stage.plan" + | "podcast.stage.kaynak" + | "podcast.stage.metin" + | "podcast.stage.ingest" + | "podcast.stage.script" + | "podcast.stage.scriptler" + | "podcast.stage.quiz" + | "podcast.stage.tts" + | "podcast.stage.ses" + | "podcast.stage.mux" + | "podcast.stage.done" | "podcast.etaHint" | "podcast.format.duz_okuma" | "podcast.format.tek_ogretici" diff --git a/src/lib/podcast-stage-labels.test.ts b/src/lib/podcast-stage-labels.test.ts new file mode 100644 index 0000000..fc48603 --- /dev/null +++ b/src/lib/podcast-stage-labels.test.ts @@ -0,0 +1,24 @@ +import { expect, test } from "vitest"; +import { en } from "@/i18n/locales/en"; +import { tr } from "@/i18n/locales/tr"; +import type { MessageKey } from "@/i18n/messages"; +import { PODCAST_STAGE_KEYS, podcastStageLabel } from "./podcast-stage-labels"; + +const locales = { en, tr } as const; + +test("every known stage has a non-empty label in both locales", () => { + for (const stage of Object.keys(PODCAST_STAGE_KEYS)) { + for (const [name, dict] of Object.entries(locales)) { + const label = podcastStageLabel(stage, (key) => dict[key]); + expect(label, `${name}:${stage}`).not.toBe(""); + expect(label, `${name}:${stage}`).not.toBe(stage); + } + } +}); + +test("an unknown stage falls back to the raw key", () => { + const t = (key: MessageKey) => key; + expect(podcastStageLabel("synthesizing", t)).toBe("synthesizing"); + expect(podcastStageLabel("toString", t)).toBe("toString"); + expect(podcastStageLabel("", t)).toBe(""); +}); diff --git a/src/lib/podcast-stage-labels.ts b/src/lib/podcast-stage-labels.ts new file mode 100644 index 0000000..125eb3d --- /dev/null +++ b/src/lib/podcast-stage-labels.ts @@ -0,0 +1,36 @@ +import type { MessageKey } from "@/i18n/messages"; + +type Translate = (key: MessageKey, params?: Record) => string; + +/** + * Pipeline stage keys the job trail can show. + * + * The backend forwards `stage` as a free string (`PodcastJobStatus.stage`). + * The frontend records `queued` itself before the first poll; the service + * then reports one of its mode tuples and `done` when the job finishes: + * simulate `ocr → plan → script → tts → mux`, API `kaynak → metin → script → + * tts → mux`, local `ingest → scriptler → quiz → ses`. `failed` / `cancelled` + * are job states, not stages — a cancel clears the stage, a failure keeps + * the last one. + */ +export const PODCAST_STAGE_KEYS = { + queued: "podcast.stage.queued", + ocr: "podcast.stage.ocr", + plan: "podcast.stage.plan", + kaynak: "podcast.stage.kaynak", + metin: "podcast.stage.metin", + ingest: "podcast.stage.ingest", + script: "podcast.stage.script", + scriptler: "podcast.stage.scriptler", + quiz: "podcast.stage.quiz", + tts: "podcast.stage.tts", + ses: "podcast.stage.ses", + mux: "podcast.stage.mux", + done: "podcast.stage.done", +} as const satisfies Record; + +/** Display label for a podcast stage key; an unknown key shows as sent. */ +export function podcastStageLabel(stage: string, t: Translate): string { + if (!Object.hasOwn(PODCAST_STAGE_KEYS, stage)) return stage; + return t(PODCAST_STAGE_KEYS[stage as keyof typeof PODCAST_STAGE_KEYS]); +}