How zggsong/stranslate works
Project Type and Purpose
• STranslate is a desktop, full‑stack, ready‑to‑go translation and OCR tool built on the .NET ecosystem using WPF for the UI.
• It follows the MVVM (Model‑View‑ViewModel) pattern, bundles local inference engines (PaddleOCR) and interfaces with many external translation/OCR services via HTTP/SDKs. An auto‑updater (in Rust) and packaging scripts round out the toolchain.
High‑Level Architectural Components
a. Presentation Layer (WPF Frontend)
• Components: Views (.xaml + .cs in src/STranslate/Views), Styles (src/STranslate.Style), Resources.
• Role: Render UI, bind to ViewModels, host user interactions (text input, OCR screenshots, preferences).
b. Application Logic (ViewModels)
• Components: src/STranslate/ViewModels and subfolders (InputViewModel, OCRViewModel, PreferenceViewModels, etc.).
• Role: Expose properties/commands to Views, orchestrate translation/OCR flows, handle user preferences.
c. Domain Layer (Models & Interfaces)
• Components: src/STranslate.Model defines ITranslator, IOCR, TranslationModel, ConfigModel, HistoryModel, etc.
• Role: Encapsulate business entities, define interfaces for translator/OCR/TTS plugins, manage configuration and history.
d. Service Layer (Utilities & Logging)
• Components:
– src/STranslate.Util: HTTP clients, clipboard, file, proxy management, authentication helpers.
– src/STranslate.Log: ILogger implementations (NLog, Serilog), LogService.
• Role: Provide cross‑cutting concerns—network calls to external APIs or local inference, logging, file I/O, proxy configuration, update checking.
e. External Integration & Extras
• Built‑in inference: PaddleOCR models in src/STranslate/inference, packaged via upx in STranslate.Extra.
• Volcengine OCR DLL (Go code) in STranslate.Extra/volcengine‑dll.
• Translator/OCR service plugins: implementations of ITranslatorLLM, IOCRLLM in Model + PreferenceViewModel/OCRViewModel.
f. Updater
• Component: src/STranslate.Updater (Rust/Cargo project).
• Role: Checks for new releases, downloads updates, triggers installer/uninstaller scripts.
g. Deployment & Build
• Scripts: PowerShell (.ps1), batch (.bat), micasetup.json, nuget.config.
• CI: .github/workflows/dotnet.yml for building, testing, packaging.
Component Relationships & Data Flow
• User action in View → bound to ViewModel command → ViewModel calls domain service (ITranslator, IOCR) implemented in Model → Model uses Util (HttpUtil, PaddleOCRHelper, ExternalCallHelper) → external API or local inference produces result → returned up to ViewModel → UI updated.
• Logging hooks into Util/Model layers for each operation.
• Configuration & History read/write managed by ConfigModel & HistoryModel via SqlHelper or file I/O in Util.
• Updater runs independently or on startup to check remote version → downloads and invokes installer.ps1.
Architectural Patterns & Design Principles
• MVVM: Clear separation of UI (Views), presentation logic (ViewModels), business logic/interfaces (Models).
• Dependency inversion: Use of interfaces (ITranslator, IOCR, ITTS) to allow plugin‑style extensibility.
• Modularization: Each concern (Styling, Logging, Utilities, Updater, Extras) lives in its own project.
• Single responsibility: Helpers/utilities each focus on one task (ClipboardUtil, HttpUtil, ProxyUtil, etc.).
• Extensibility: New translator/OCR engines drop in by implementing interfaces and registering in ViewModel factories.
Technologies & Frameworks to Call Out
• .NET 6+ (WPF), C#
• MVVM pattern
• JSON for config (version-info.json, micasetup.json)
• Rust for the STranslate.Updater component
• Go for Volcengine OCR DLL wrapper
• Upx for executable compression
• PowerShell/batch for installer/uninstaller scripts
• NLog/Serilog for logging
• HTTP/REST clients for external APIs (Baidu, Google, Azure, OpenAI, etc.)
• PaddleOCR for on‑device OCR inference