π 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
Clone the repository:
git clone https://github.com/LM-Kit/lm-kit-net-samplesNavigate to the project directory:
cd lm-kit-net-samples/console_net/text_translatorBuild and run the application:
dotnet build dotnet runFollow 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
π Related Content
- Translate and Localize Content: step-by-step guide for configuring translation parameters, language detection, and localization workflows.
- Build Multilingual Audio Translation Pipeline: extend translation to spoken content by combining speech-to-text with text translation.
- Language Detection from Document Demo: companion demo that detects the language of document content before translation.