Translate
Contents
[
Hide
]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)
Parameter | Type | Description |
---|---|---|
sourceDocument | Document | The document to be translated. |
targetLanguage | Language | The 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
- class Document
- enum Language
- interface IAiModelText
- namespace Aspose.Words.AI
- assembly Aspose.Words