Table of Contents

Method Translate

Namespace
LMKit.Translation
Assembly
LM-Kit.NET.dll

Translate(string, Language, CancellationToken)

Converts plain text into a specified target language while maintaining the original layout.

public string Translate(string text, Language language, CancellationToken cancellationToken = default)

Parameters

text string

The text to translate; cannot be null or whitespace.

language Language

A member of the Language enumeration specifying the target language code for the translation.

cancellationToken CancellationToken

Optional. A CancellationToken for handling cancellation requests.

Returns

string

The translated text.

Examples

using LMKit.Translation;
using LMKit.Model;
using System;

// Initialize the language model (LLM)
LLM languageModel = new LLM("path/to/your/model");

// Create an instance of TextTranslation using the LLM
TextTranslation textTranslation = new TextTranslation(languageModel);

// Text to translate
string text = "This is a sample text to be translated.";

// Translate the text to German
string translatedText = textTranslation.Translate(text, Language.German);

Console.WriteLine(translatedText);
// Output: "Dies ist ein Beispieltext, der übersetzt werden soll."

Remarks

This method is designed to handle text of any size, ensuring that the structure and formatting of the original content are preserved in the translation.

Exceptions

ArgumentException

Thrown if the input text is null or whitespace.