I do not know how to translate two languages ​with Tesseract.js

739 Views Asked by At

I'm trying to use the Tesseract.js library to convert an ID image to text but the ID has two English and Arabic languages ​​and it totally ruins my translation. Is there a way to translate two languages ​​or ignore one language? I have attached my code, here in the code I only translate from English and everything in Arabic destroys the output.

const convertImageToText = useCallback(async () => {
    if (!selectedImage) return;
    await worker.load(); // Load the tesseract.js worker
    await worker.loadLanguage("eng"); // Load the english language
    await worker.initialize("eng"); // Initialize the english language
    const { data } = await worker.recognize(selectedImage);
    setTextResult(data.text);
}
1

There are 1 best solutions below

0
On

If we want to add more than one language option at the same time, it will be enough to put '+' between them.

await worker.loadLanguage('eng+ara'); 


await worker.initialize('eng+ara');