How yang-haruka/linguaharu works
Project type and purpose
• This is a Python-based full-stack translation tool (LinguaHaru) that provides a web UI for uploading documents, runs format-specific translation pipelines, and calls LLM engines (local or online) to produce output.
File structure
• Top-level:
• app.py / app_temp.py – entry point for the web server/UI
• config/ – holds API credentials, prompts, system settings
• llmWrapper/ – abstraction layer over local (Ollama) and online model APIs
• pipeline/ – orchestrators for each file type’s end-to-end translation flow
• translator/ – per-format translation logic (Word, Excel, PDF, etc.)
• textProcessing/ – text splitting, token counting, translation checking
• utils/ – queue manager, process launcher, UI helpers, logging
• No persistent database; files flow through in-memory or temporary storage
• External dependencies: online LLM services (OpenAI, Deepseek, etc.), local Ollama runtime
Key README insights
• Single-page web UI served at http://127.0.0.1:9980
• “One-click” pipeline: upload → pipeline → LLM call → reassembly → download
• Configurable engines, prompts, multilingual support
Main components & interactions
a. Frontend (Web UI)
• Served by app.py (Flask/FastAPI/Starlette or equivalent)
• Upload endpoint, status/progress, download link
b. Backend API Server
• HTTP controller in app.py → delegates to utils/main_app and utils/translation_process
• Reads config/app_queue for task scheduling
c. Pipeline Orchestrator
• pipeline/*.py modules select the right flow based on file type
• Enqueue tasks, manage multithreading/multiprocessing
d. Translator Modules
• translator/*_translator.py handle I/O, format parsing, layout preservation
• PDFMathTranslate subpackage for PDF specifics
e. Text Processing
• base_translator, text_separator, calculation_tokens, translation_checker
• Splits large text, counts tokens, ensures chunk correctness
f. LLM Wrapper
• llm_wrapper.py picks between local Ollama or remote APIs (OpenAI, Deepseek, Gemini…)
• online_translation.py / offline_translation.py implement HTTP or local CLI calls
g. Configuration
• config/api_config/*.json, config/system_config.json, config/prompts/*.json
• languages_config.py and load_prompt.py dynamically supply parameters
h. External Services & Models
• Local model repository under models/ (Qwen, etc.)
• Remote API endpoints
Architectural patterns & design principles
• Modular “pipeline” pattern: each file format has its own pipeline class
• Separation of concerns: UI layer, orchestration layer, format translators, LLM calls, text utilities
• Config-driven behavior: engines, prompts, languages all abstracted via JSON
• Task queue + multiprocessing for concurrency
Detail
• Both local and online LLM branches
• Where prompts/config merge into the workflow
• Flow of a single “translate document” request end-to-end