Fix OCR dropping German umlauts by loading the German model

Tesseract only loaded the English model, which has no ä/ö/ü/ß, so they were
misread as plain letters. Load deu+eng and normalize output to NFC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Claudio Schaad 2026-11-02 17:00:01 +01:00
parent be421d83cb
commit 7107846624

View file

@ -2,13 +2,15 @@ let workerPromise: Promise<import("tesseract.js").Worker> | null = null;
function getWorker() { function getWorker() {
if (!workerPromise) { if (!workerPromise) {
workerPromise = import("tesseract.js").then(({ createWorker }) => createWorker("eng")); // "deu" is needed for umlauts and ß; the English model can't produce them.
workerPromise = import("tesseract.js").then(({ createWorker }) => createWorker("deu+eng"));
} }
return workerPromise; return workerPromise;
} }
function cleanUpText(raw: string): string { function cleanUpText(raw: string): string {
return raw return raw
.normalize("NFC")
.replace(/[ \t]+\n/g, "\n") .replace(/[ \t]+\n/g, "\n")
.replace(/\n{3,}/g, "\n\n") .replace(/\n{3,}/g, "\n\n")
.trim(); .trim();