Automate document translation using Google Gemini AI models with Aspose.Words for .NET. Translate DOC, DOCX, RTF, PDF, HTML, Markdown, ODT, TXT, and EPUB files into over 300 languages while preserving the original layout and formatting. The AI-based engine detects the source language automatically — even in multi-language documents — and leaves untranslated only those fragments it cannot identify.
Authentication requires a Google API key. For a full list of supported AI models, see the API Reference.
Start translating documents in C# today — try the live demo above.
dotnet add package Aspose.Words
Copy
using Aspose.Words;
Document doc = new Document("Document.docx");
string apiKey = Environment.GetEnvironmentVariable("API_KEY");
// Use Google generative language models.
AiModel model = AiModel.Create(AiModelType.GeminiFlashLatest).WithApiKey(apiKey);
Document translatedDoc = model.Translate(doc, Language.Arabic);
translatedDoc.Save("Output.docx");
using Aspose.Words;
Document doc = new Document("Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
AiModel model = new CustomAiModel("my-model-24b", "https://your-server.com/v1").WithApiKey("");
Document translatedDoc = model.Translate(doc, Language.Arabic);
translatedDoc.Save("Output.docx");
class CustomAiModel : OpenAiModel
{
private readonly string mUrl;
internal CustomAiModel(string name, string url) : base(name) { mUrl = url; }
public override string Url => mUrl;
}
There are three alternative options to install "Aspose.Words for .NET" onto your system. Please choose one that resembles your needs and follow the step-by-step instructions:
Our product is fully cross-platform and supports all major .NET implementations:
As far as .NET code doesn't depend on the underlying hardware or operating system, but only on a Virtual Machine, you are free to develop any kind of software for Windows, macOS, Android, iOS and Linux. Just make sure you have installed the corresponding version of .NET Framework, .NET Core, Windows Azure, Mono or Xamarin.
We recommend using Microsoft Visual Studio, Xamarin, and MonoDevelop integrated development environments to create C#, F#, VB.NET applications.
Fore more details please refer to Product Documentation.