Automate document translation using Google Gemini AI models with Aspose.Words for Node.js via .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 JavaScript today — try the live demo above.
npm install @aspose/words
Copy
const aw = require('@aspose/words');
const doc = new aw.Document("Document.docx");
const apiKey = process.env.API_KEY;
// Use Google generative language models.
const model = aw.AI.AiModel.createGemini15Flash();
model.setApiKey(apiKey);
const translatedDoc = model.translate(doc, aw.AI.Language.Arabic);
translatedDoc.save("Output.docx");
const aw = require('@aspose/words');
const doc = new aw.Document("Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
const model = new CustomAiModel("my-model-24b", "https://your-server.com/v1");
model.setApiKey("");
const translatedDoc = model.translate(doc, aw.AI.Language.Arabic);
translatedDoc.save("Output.docx");
class CustomAiModel extends aw.AI.OpenAiModel {
constructor(name, url) {
super(name);
this._url = url;
}
get url() {
return this._url;
}
}
We host our Node.js via .Net packages in NPM repositories. Please follow the step-by-step instructions on how to install "Aspose.Words for Node.js via .NET" to your developer environment.
This package is compatible with Node.js 14.17.0 or higher.