Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apps/lingua/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 25 additions & 0 deletions apps/lingua/web/assets/lingua-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
4 changes: 2 additions & 2 deletions apps/lingua/web/assets/lingua-mobile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion apps/lingua/web/assets/lingua-web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion apps/lingua/web/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
'./',
Expand Down
Loading