使用 Google Gemini AI 模型和 Aspose.Words for Node.js via .NET 自动化文档翻译。将 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 文件翻译成 300 多种语言,同时保留原始布局和格式。基于 AI 的引擎会自动检测源语言——即使在多语言文档中——并仅对无法识别的片段保持未翻译状态。
身份验证需要 Google API 密钥。有关支持的 AI 模型完整列表,请参阅 API Reference。
立即在 JavaScript 开始翻译文档——尝试上方的实时演示。
npm install @aspose/words
复制
const aw = require('@aspose/words');
const doc = new aw.Document("Document.docx");
const apiKey = process.env.API_KEY;
// 使用 Google 生成式语言模型。
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.