Translate

IAiModelText.Translate method

Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating.

public Document Translate(Document sourceDocument, Language targetLanguage)
ParameterTypeDescription
sourceDocumentDocumentThe document to be translated.
targetLanguageLanguageThe language into which the document will be translated.

Return Value

A new Document object containing the translated document.

Examples

Shows how to translate text using Google models.

Document doc = new Document(MyDir + "Document.docx");

string apiKey = Environment.GetEnvironmentVariable("API_KEY");
// Use Google generative language models.
IAiModelText model = (IAiModelText)AiModel.Create(AiModelType.Gemini15Flash).WithApiKey(apiKey);

Document translatedDoc = model.Translate(doc, Language.Arabic);
translatedDoc.Save(ArtifactsDir + "AI.AiTranslate.docx");

See Also