Urgent.News

What's breaking now, across thousands of outlets.

Tech

LingoGeek: translating whole documents offline with CTranslate2 and a Python desktop app

Hi DEV! Pasting a document into a translation site works right up until the formatting matters. Then you get a wall of text back and rebuild the layout by hand. And if the document is a contract or a medical letter, you have just uploaded it to somebody else's server to save yourself ten minutes. LingoGeek translates the file rather than the text: .docx comes back as .docx, with headings, tables…

LingoGeek offers a desktop application that translates entire documents, including .docx and PDF files, while preserving their formatting and layout. Unlike traditional translation sites, LingoGeek keeps documents intact by returning them in their original file type, whether that be .docx or PDF. The application also supports subtitles, maintaining their timing and cue numbers.

The need for LingoGeek arose from the limitations of online translation platforms. When a user uploads a document to such a site, the formatting often becomes distorted, requiring manual reformatting. This is particularly problematic for legal or medical documents, where accurate formatting is crucial.

LingoGeek addresses this issue by performing the translation locally on the user's device. This approach not only ensures the document's integrity but also eliminates the need for per-word charges typically associated with online translation services. The developer chose Python as the programming language for the application, utilizing a desktop app built with pywebview, combined with FastAPI and uvicorn for server-side handling.

The translation process involves complex handling of document structures, especially for word documents where a single sentence can be split across multiple runs with varying formatting. The application effectively translates these documents while reapplying the original formatting. The tech stack also includes ctranslate2, sentencepiece, python-docx, pypdf, and pydantic for various tasks, including inference and document handling.

The application is still in its early stages, with some limitations including the lack of code signing for the installer and difficulties with complex PDF layouts. The developer is open to suggestions for new language pairs to add to the application. For more information, users can visit the LingoGeek website at https://techygeekshome.info/lingogeek/ or check out the GitHub repository at https://github.com/techygeekshome/LingoGeek. A video demonstration is available at https://youtu.be/hOF9UWpFFd8.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Fixed Is Not Repaired

Two Posts With Holes In Them For two and a half weeks, two posts on this blog referenced diagrams that did not load. Not a rendering quirk — a 404.

More from Saturday 12 September →