How xapajiamnu/translatelocally works
Project Type and Purpose
• This is a native Qt-based desktop application (C++17) with both GUI and CLI interfaces.
• It embeds the Marian/Bergamot translation engine, manages local translation models, and can serve as a Native Messaging host for browser extensions.
• It provides translation services entirely on the user’s machine, including model download, management, and translation pipelines (pivoting, quantization).
High-Level Architecture Overview
Break the system into four logical layers:
A. Presentation Layer (User Interfaces)
• GUI Module (Qt Widgets)
– mainwindow.ui, dialogs under src/settings, UI controllers (mainwindow.cpp, TranslatorSettingsDialog)
• CLI Module
– CLI parsing (CLIParsing.h), CommandLineIface, NativeMsgIface, NativeMsgManager
B. Core Application Logic
• Model Manager (inventory/ModelManager) – tracks installed models on disk
• Translation Controller (Translation.cpp/h, AlignmentWorker, AlignmentHighlighter)
• Network & Download Manager (Network.cpp/h) – HTTP download via Qt Network, wrapping libarchive for extraction
C. Translation Engine Integration
• MarianInterface (src/MarianInterface.cpp/h) – C++ wrapper over bergamot-translator (submodule in 3rd_party)
• 3rd_party/bergamot-translator – the actual inference engine
D. Build & Packaging Toolchain
• CMake project files (CMakeLists.txt, cmake/ directory)
• Packaging scripts (dist/, logo/) for .dmg, AppImage, PKGBUILD, Windows resources
Component Relationships and Data Flows
• GUI or CLI receives a user request → forwards to Core Translation Controller
• Controller queries Model Manager for model path → invokes MarianInterface
• MarianInterface calls into bergamot-translator binary/API → returns tokens/strings
• Controller posts results back to GUI view or CLI stdout
• For model download: Core invokes Network module → HTTP GET → libarchive extraction → updates Model Manager
• Native Messaging: NativeMsgManager wraps the CLI controller, exposing JSON in/out
Key Architectural Patterns & Principles
• MVC/MVP style in the GUI: UI files define Views, mainwindow.cpp & dialogs act as Controllers, ModelManager is the Model
• Single-process monolith but logically layered (UI / Core Logic / Engine)
• Dependency injection via CMake: choice of BLAS provider (MKL vs OpenBLAS), Qt version, external archives
• Plugin-style support for multiple model repositories: repository definitions loaded at runtime
Important Technologies & Frameworks
• Qt ≥5 (Widgets, Network, LinguisticTool, SVG)
• CMake build system, custom cmake modules for packaging and versioning
• Intel MKL (preferred BLAS) or optionally OpenBLAS
• libarchive for model tarball extraction
• bergamot-translator (Marian fork) for the core MT engine
• Native Messaging protocol (JSON over stdin/stdout)