Translate a Document
Document translation is a frequently needed option in the age of high digitalization. Aspose.Words supports document translation using Google generative language models, which allows developers to translate texts content into more than 300 languages.
Use the Translate method to translate your documents into any language represented in the Language enumeration. Note that if the source document contains several languages, the Google AI-based model will be able to translate all supported languages. If the model cannot recognize the language in some text fragments, then you will be returned a document with these untranslated fragments and with the rest of the text translated.
The following code example shows how to use the Gemini 1.5 Flash model in Aspose.Words to translate a document into Arabic:
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");