$ show DavidVentura/offline-translator
This repository implements a fully offline, multi-modal translation application for Android. It supports text translation, image translation via OCR (PaddleOCR, Tesseract), document translation (PDF, ODT, EPUB, TXT), live camera translation with GPU-accelerated overlay, screen capture translation, a built-in web browser with adblock and reader mode, text-to-speech (Piper, Kokoro, MMS, Coqui, Mimic3), and dictionary lookup from Wiktionary data. All inference runs on-device using downloaded language packs (translation models, OCR models, TTS voices, dictionaries). The app is built with Kotlin and Jetpack Compose for the UI, with a native Rust core (via UniFFI and JNI) for performance-critical tasks like translation, OCR, TTS synthesis, and GPU rendering. It also includes a Python-based catalog generation pipeline for managing model distributions and a standalone i18n viewer tool for translation management. The architecture is a monolith with multiple foreground services, accessibility services, and overlay windows, all orchestrated by a central ViewModel and a Rust-based catalog handle. While primarily an application, the repository also contains data/research elements in the form of model catalogs, evaluation metrics, and build-time data processing scripts.
The LLM identified 5 files worth highlighting for reuse:
A heavily customized port of Arc90's Readability algorithm, bundled as a static asset. It extracts article content from arbitrary HTML pages, handling edge cases like nested elements, bylines, and site-specific quirks. This script is fully self-contained and can be reused in any web content processing pipeline (e.g., browser extensions, server-side scrapers) with minimal adaptation.
The main Rust library that exposes translation, OCR, TTS, document processing, and catalog management to Kotlin via UniFFI and JNI. It uses feature flags (e.g., `dictionary`, `tts`, `pdf`, `ppocr`) to compile only needed functionality, making it modular and reusable for other Android projects requiring on-device ML. The pattern of combining UniFFI for high-level interfaces with hand-rolled JNI for performance-critical paths (e.g., zero-copy bitmap access) demonstrates advanced cross-language integration.
A factory class that programmatically creates pill buttons, toolbars, language pickers, and menus for overlay windows (accessibility service, screen translate). It provides a consistent, reusable set of UI components that can be instantiated without XML layouts, making it ideal for dynamic overlay UIs in Android. The design is decoupled from specific use cases and can be extracted for any app needing floating UI elements.
A Lens-style word selection overlay with draggable handles, a magnifier, and floating action buttons (Copy, Share, Search). It handles touch events, word boundary detection, and visual feedback in a self-contained composable. This component can be reused in any Android app that needs interactive text selection on images or custom surfaces, independent of the translation context.
A standalone HTML tool that renders an SVG-based translation editor, allowing translators to edit UI strings directly on a visual mockup. It fetches SVG, keys JSON, and strings.json, integrates with Weblate for saving, and supports inline editing with foreignObject. This tool is reusable for any project that wants a visual translation workflow, independent of the Android app.