Translate(text, target)
Translate a string to the target Language.
The TextTranslation engine translates plain strings, image
content, and document attachments across 100+ languages. Layout and
formatting are preserved during translation, custom system prompts and
few-shot examples shape the output for your domain, and every byte stays
on the machine that ran the inference.
Translate(text, target)Translate a string to the target Language.
TranslateAsync(...)Async overloads with cancellation tokens.
TranslationProgressToken-by-token progress events for streaming UIs.
Attachment inputTranslate text inside PDFs, Office docs, and images.
Cloud translation APIs typically return a flat translated string and discard
the layout of the input. TextTranslation takes a different
approach: it preserves paragraph breaks, list bullets, code blocks, table
cells, and inline emphasis so a translated document remains usable in your
application without a layout post-process.
Markdown, HTML, and PDF structure are kept intact during translation. Paragraph and list boundaries map 1:1 between source and target.
Override the default translator system prompt to enforce house style, glossary terms, register (formal vs casual), or domain conventions.
Pass (input, output) pairs alongside your translation request to teach the model your preferred phrasing for jargon, brand terms, and idioms.
Subscribe to TranslationProgress for token-by-token updates. Build responsive translation UIs that display output as the model generates.
Translate text inside images and PDFs through the same API. The model performs OCR or VLM analysis transparently when given an Attachment.
Both blocking and Task-based overloads. Async variants accept CancellationToken so long translations integrate cleanly with UI patterns.
From a single line of text to a streaming multi-paragraph translation, the same class handles each shape.
using LMKit.Model; using LMKit.Translation; using LMKit.TextGeneration; var model = LM.LoadFromModelID("qwen3.5:4b"); var translator = new TextTranslation(model); string source = "The forecast suggests heavy snowfall across the highlands."; string german = translator.Translate(source, Language.German); string japanese = translator.Translate(source, Language.Japanese); Console.WriteLine(german); Console.WriteLine(japanese);
using LMKit.Translation; using LMKit.TextGeneration; var translator = new TextTranslation(model); // Teach the engine your preferred technical terminology. var examples = new List<(string, string)> { ("flush the cache", "vider le cache"), ("warm up the model", "pré-charger le modèle"), ("hot-swap an adapter", "permuter un adaptateur à chaud") }; string systemPrompt = "You translate technical .NET documentation into French. Keep code fences and inline code as-is."; var promptData = new TextTranslation.TranslationPromptData(systemPrompt, examples); string output = translator.Translate(text, Language.French, promptData);
using LMKit.Translation; using LMKit.TextGeneration; var translator = new TextTranslation(model); // Stream tokens to the UI as they're produced. translator.TranslationProgress += (sender, e) => { Console.Write(e.Token); }; string source = await File.ReadAllTextAsync("article.txt"); string spanish = await translator.TranslateAsync( source, Language.Spanish, cancellationToken); Console.WriteLine($"\nDone. {spanish.Length} chars.");
TextTranslation.GetTrainingData returns curated training pairs
you can feed into LoraFinetuning to specialise a base model for
your translation domain. Combine with custom few-shot examples at inference
time for the best of both worlds: the LoRA learns your structural patterns,
the few-shot keeps glossary terms exact.
Legal contracts, NDAs, internal memos, M&A material. Translate without sending text to any third-party endpoint.
Defense, research labs, isolated facilities. Translation works without any internet connectivity.
Translate millions of customer messages with a fixed license cost instead of per-token cloud fees that scale linearly.
Embed real-time translation inside desktop and mobile apps. Sub-second latency without round-trips.
Combine with DocumentRag and OCR to translate scanned PDFs, invoices, and contracts inline.
Pin brand names, product SKUs, and technical jargon via few-shot examples. Beat generic cloud translators on domain consistency.
TextTranslationMain class. Translate and TranslateAsync overloads accept text, target Language, optional TranslationPromptData, and optional CancellationToken.
TranslationPromptDataPair a custom SystemPrompt with a list of (Input, Output) few-shot examples. Override per-call to specialise translation behaviour.
TranslationProgressEvent fired with each generated token. Use for streaming UI updates and progress bars.
LanguageEnumeration of all supported source and target languages.
Need to identify the source language first? See the Language Detection page.
Working console demos on GitHub, step-by-step how-to guides on the docs site, and the API reference for the classes used on this page.
Console demo: translate text on-device with quality controls.
Open on GitHub → How-to guidePractical translation patterns at scale.
Read the guide → How-to guideEnd-to-end pipeline for translating document corpora.
Read the guide →Fixed license, unlimited tokens, zero data egress.