I built a 100% local comic translation engine in Rust that hooks into Ollama / LM Studio with sliding dialogue context and ONNX vision models (Demo video)

Developing a Self-Contained AI-Powered Comic Translation Engine Using Rust

In the rapidly evolving landscape of digital comics and manga localization, leveraging artificial intelligence (AI) offers exciting opportunities to streamline translation workflows. Recently, I embarked on creating a fully autonomous, local-first comic translation system built entirely in Rust. This innovative pipeline integrates powerful machine learning models, computer vision, and multilingual optical character recognition (OCR)—all without relying on cloud services or external dependencies.

The Challenge of Context Preservation in Comic Translation

Automated translation of comics presents unique challenges, primarily due to the importance of context. Traditional OCR-based approaches often process text boxes individually, leading to issues like:

  • Loss of speaker identity
  • Frequent pronoun swaps
  • Inconsistent character name references across pages

To overcome this, effective translation systems need to intelligently maintain dialogue context, ensuring character consistency and narrative coherence throughout the comics.

Introducing XianScan: A Rust-Based, Local Comic Translation Workflow

The core component of this project is XianScan, a standalone, open-source translation engine designed to run entirely on local hardware. Its architecture combines cutting-edge AI models, computer vision techniques, and a user-friendly interface, all encapsulated within a single, easy-to-deploy binary.

Demo Video: Watch the full translation pipeline in action [here].

The AI Stack: How It All Comes Together

1. Vision & Detection

At the forefront of scene analysis is Koharu RF-DETR Seg 2XL, a robust vision transformer model. It performs pixel-level segmentation of speech bubbles and comic panels, accurately delineating dialogue regions with polygon masks, even amid complex artwork layouts.

2. Multilingual Optical Character Recognition (OCR)

PaddleOCR enables the extraction of dialogue text in over ten languages, including vertical CJK scripts and various horizontal formats. Its multilingual support ensures broad applicability across manga, manhwa, and manhua.

3. Flexible Language Model (LLM) Engine

The engine supports both local and cloud-based language models. Local runtimes like Ollama and LM Studio are compatible, alongside cloud APIs such as Gemini, OpenAI, Groq, and OpenRouter. To maintain conversational consistency, a sliding dialogue buffer preserves recent context, while glossaries help keep character names and lore consistent throughout chapters.

4. Neural Inpainting for Dialogue Bubbles

LaMa-based neural inpainting cleanses dialogue bubbles, removing original text cleanly without damaging underlying artwork. This ensures a seamless canvas for the translated text.

5. Typesetting and Text Insertion

Automated calculation of font size, stroke outlines, and text wrapping ensures that translated dialogues fit naturally within speech bubbles, maintaining the visual integrity of the original art.

Advantages of a Single Binary Solution

One of the key design choices was packaging the entire translation pipeline into a single executable file. This approach simplifies deployment, requiring no complex environment setups like Python, Conda, or Node.js. The Rust binary includes all necessary models, OCR weights, and UI components, making it playable on standard laptops. It intelligently leverages GPU acceleration via DirectML, CoreML, or CUDA when available, ensuring optimal performance.

User Experience and Integration

The system facilitates multiple workflows:

  • Web-based translation: Use browser extensions to translate directly from source websites.
  • Library management: Organize and review translations through an integrated web UI.
  • Chapter streaming: Export and stream finished chapters over a local Wi-Fi network, compatible with readers like Mihon or Tachiyomi (including TachiyomiSY, J2K, and Aniyomi) on mobile devices.

Open-Source and Community-Driven

Currently in its initial public beta, XianScan is open-source under the MIT license. I invite the community to contribute, test, and provide feedback—particularly on dialogue context management, prompt design, and model performance.

Final Thoughts

This project demonstrates that a comprehensive, high-quality comic translation pipeline can operate entirely offline, leveraging the efficiency and safety of local computation. As AI models continue to improve, tools like XianScan promise to empower translators and fans to enjoy and share localized comics seamlessly, privately, and cost-effectively.

Your feedback on the dialogue context handling, prompt strategies, or model choices would be invaluable—please get in touch or contribute to the project!


Note: Since this is a beta release, expect some bugs and areas for improvement. Your patience and input are appreciated.

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *