diff --git a/apps/lingua/README.md b/apps/lingua/README.md index 04465785..f79ec47e 100644 --- a/apps/lingua/README.md +++ b/apps/lingua/README.md @@ -17,7 +17,9 @@ Both are the web edition (https://juw12.github.io/projects/lingua/) in its own w - Mobile translate and Read picture work in them. Live caption capture needs a browser that can share the screen (Chrome, Edge or Firefox on the Mac), and the floating caption window over Teams is the Windows app only. - They call the translation gateway you set, straight from the page. A gateway on plain `http` or one only reachable from the office network (the company one) cannot be called this way: use **Share to phone** from the laptop for that, as described under [Versions](#versions-laptop-web-iphone-android). -Each build is opened on GitHub's machines before it is published: on an Apple-silicon Mac and an Intel Mac the page loads, the app starts and can store data; on an Android emulator it installs, opens and stays up. No translation was made in them, and no Mac or phone of ours has run them yet. +Each build is opened on GitHub's machines before it is published: on an Apple-silicon Mac and an Intel Mac the page loads, the app starts and can store data; on an Android emulator it installs, opens and stays up. A translation was made on the page itself in WebKit (the Mac window's engine) and in Chromium as a phone, against a stand-in gateway on the test Mac: the page asked, the answer was shown, and a gateway that is gone is reported as a failure. None was made against a real gateway inside the two apps, and no phone of ours has run them yet. + +Fixed on 23 Nov 2026: Web capture and Mobile translate showed `[object Promise]` in place of every translation and said "Translated." whether or not the gateway had answered (the pipeline, ported from the laptop app, did not wait for the browser's network call). Read picture was not affected. The same pages are what **Share to phone** serves, so the Windows app carries the fix from its next build. ## Status diff --git a/apps/lingua/web/assets/lingua-core.js b/apps/lingua/web/assets/lingua-core.js index b454fefa..4572c6f3 100644 --- a/apps/lingua/web/assets/lingua-core.js +++ b/apps/lingua/web/assets/lingua-core.js @@ -200,6 +200,31 @@ export class CaptionPipeline { return window.slice(); } + // In a browser the translate function is a network call and hands back a promise. update() stays as it is + // in the laptop app it was ported from (there translating is not asynchronous); this waits for every + // translation update() started and puts the text into the lines. Without it the page showed + // "[object Promise]" and said "Translated." whether or not the gateway had answered. + async updateAsync(rawText, onChunk) { + this.update(rawText, onChunk); + const waiting = (line) => line.translation && typeof line.translation.then === "function"; + try { + for (const line of this._window) { + if (!waiting(line)) continue; + const text = await line.translation; + this.cache[line.original] = text; + line.translation = text; + } + } catch (err) { + // Forget what did not arrive, so the next try asks the gateway again instead of keeping the failure. + for (const line of this._window) { + if (waiting(line)) delete this.cache[line.original]; + } + this.reset(); + throw err; + } + return this._window.slice(); + } + reset() { this._prevNorm = []; this._window = []; diff --git a/apps/lingua/web/assets/lingua-mobile.js b/apps/lingua/web/assets/lingua-mobile.js index f9d76df6..c4da83b3 100644 --- a/apps/lingua/web/assets/lingua-mobile.js +++ b/apps/lingua/web/assets/lingua-mobile.js @@ -182,7 +182,7 @@ async function translatePastedText() { try { // Feed the pasted text into the pipeline as a single OCR frame so the // dedup + live + speaker logic is identical to the desktop path. - const lines = pipeline.update(text); + const lines = await pipeline.updateAsync(text); const transcriptLines = transcript.add(lines); renderRows(speakerRows(transcriptLines)); setStatus("Translated.", "ok"); @@ -213,7 +213,7 @@ async function ocrAndTranslate() { setStatus("OCR returned no text.", "warn"); return; } - const lines = pipeline.update(text); + const lines = await pipeline.updateAsync(text); const transcriptLines = transcript.add(lines); renderRows(speakerRows(transcriptLines)); setStatus(`OCR + translate done (${text.split("\n").length} line(s)).`, "ok"); diff --git a/apps/lingua/web/assets/lingua-web.js b/apps/lingua/web/assets/lingua-web.js index 3daa5306..7deccf7f 100644 --- a/apps/lingua/web/assets/lingua-web.js +++ b/apps/lingua/web/assets/lingua-web.js @@ -457,7 +457,7 @@ async function processFrame() { return; } const t1 = performance.now(); - const lines = pipeline.update(text); + const lines = await pipeline.updateAsync(text); const transcriptLines = transcript.add(lines); const rows = speakerRows(transcriptLines); renderTranscript(transcriptLines, rows); diff --git a/apps/lingua/web/sw.js b/apps/lingua/web/sw.js index 22a46f74..e27ba1b3 100644 --- a/apps/lingua/web/sw.js +++ b/apps/lingua/web/sw.js @@ -4,7 +4,7 @@ * or intercepted — every call hits the network so the key in localStorage * stays usable and any model change on the gateway is picked up immediately. */ -const CACHE = 'lingua-cache-v5'; +const CACHE = 'lingua-cache-v6'; const PRECACHE = [ './',