Table of Contents

πŸ‘‰ Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/text_translator

AI Language Translation from Text and Images for C# .NET Applications


🎯 Purpose of the Demo

The Text Translator demo shows how to use LM-Kit.NET to translate text between languages and extract and translate text from images. It supports both general-purpose LLMs and Google's TranslateGemma models, which are purpose-built for high-quality translation across 55 languages with text and image inputs.


πŸ‘₯ Industry Target Audience

This sample is particularly useful for developers and organizations working on:

  • Global businesses: enable seamless multilingual communication across teams, documents, and customer interactions.
  • Content creation and localization: automatically translate articles, blogs, and marketing content to reach a wider audience.
  • Document processing: extract and translate text from scanned documents, signs, menus, and other images.
  • Education: assist language learners with accurate translations from both text and visual materials.
  • Tourism and hospitality: translate signs, menus, and printed materials captured as photos.

πŸš€ Problem Solved

Manual translation is time-consuming and requires fluency in multiple languages. Image-based content (signs, documents, screenshots) adds another layer of complexity. This demo automates both text and image translation using local AI models, ensuring consistent and accurate results without sending data to external services.


πŸ’» Sample Application Description

The Text Translator is a console application that translates text and images using AI models with automatic source language detection.

✨ Key Features

  • Text translation: enter text in any language and get an instant translation
  • Image translation: provide an image file path to extract and translate visible text (requires a vision-capable model)
  • Automatic language detection: the source language is detected before translation
  • Interactive language selection: choose from 12 preset target languages, switchable mid-session with /lang
  • Translation-specialized models: TranslateGemma 3 models are suggested for best quality across 55 languages
  • Real-time streaming: translation output streams token by token as it is generated

🧠 Supported Models

Translation-specialized (suggested):

Model VRAM Highlights
Google TranslateGemma 3 4B ~3 GB Lightweight, 55 languages, text + image input
Google TranslateGemma 3 12B ~8 GB High quality, 55 languages, text + image input

General-purpose:

Model VRAM
Google Gemma 3 4B ~4 GB
Alibaba Qwen 3.5 9B ~7 GB
Google Gemma 3 12B ~9 GB
Alibaba Qwen 3.5 27B ~18 GB

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  User Input  │────▢│  Language         │────▢│  Translation     β”‚
β”‚  (text or    β”‚     β”‚  Detection        β”‚     β”‚  Engine          β”‚
β”‚   image)     β”‚     β”‚  (DetectLanguage) β”‚     β”‚  (Translate)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                       β”‚
                                                       β–Ό
                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                              β”‚  Translated      β”‚
                                              β”‚  Output          β”‚
                                              β”‚  (streamed)      β”‚
                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

For image inputs, the model extracts visible text from the image and translates it in a single pass using vision-language capabilities.


πŸ› οΈ Getting Started

πŸ“‹ Prerequisites

  • .NET 8.0 or later
  • A vision-capable model for image translation (TranslateGemma models are recommended)

πŸ“₯ Download the Project

▢️ Running the Application

  1. Clone the repository:

    git clone https://github.com/LM-Kit/lm-kit-net-samples
    
  2. Navigate to the project directory:

    cd lm-kit-net-samples/console_net/text_translator
    
  3. Build and run the application:

    dotnet build
    dotnet run
    
  4. Follow the on-screen prompts to select a model, choose a target language, and start translating.

πŸ’‘ Example Usage

Text translation:

[French] > Hello, how are you today?

Detecting language...
Detected: English. Translating to French...

Bonjour, comment allez-vous aujourd'hui ?

Image translation:

[Spanish] > C:\photos\french_sign.png

Loading image...
Image loaded (1920x1080).
Detecting language...
Detected: French. Translating to Spanish...

Zona peatonal

πŸ”§ Troubleshooting

  • "The selected model does not support vision input": switch to a TranslateGemma model or another vision-capable model for image translation.
  • "File not found": ensure the image path is correct. You can drag and drop a file into the terminal to paste its path.
  • Translation quality: for best results, use TranslateGemma 3 12B. General-purpose models work but may produce lower-quality translations.

πŸš€ Extend the Demo

  • Add batch translation of multiple files from a directory
  • Integrate with PDF processing to translate entire documents page by page
  • Combine with speech-to-text for spoken language translation
  • Build a web API around the translation engine using LM-Kit.Server

Share