使用 Aspose.Words for Java 結合 Google Gemini AI 模型來自動化文件翻譯。將 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 檔案翻譯成超過 300 種語言,同時保留原始版面配置與格式。AI 引擎會自動偵測來源語言——即使是在多語言文件中——並且只保留無法識別的片段不予翻譯。
驗證需要 Google API 金鑰。如需支援的 AI 模型完整列表,請參閱 API 參考文件。
立即開始在 Java 中翻譯文件——試試上方的即時展示。
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>ver</version>
<classifier>jdk17</classifier>
</dependency>
複製
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
複製
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
<artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
複製
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
複製
Document doc = new Document("Document.docx");
String apiKey = System.getenv("API_KEY");
// 使用 Google 生成式語言模型。
AiModel model = AiModel.create(AiModelType.GEMINI_FLASH_LATEST).withApiKey(apiKey);
Document translatedDoc = model.translate(doc, Language.ARABIC);
translatedDoc.save("Output.docx")
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().withApiKey("");
Document translatedDoc = model.translate(doc, Language.Arabic);
translatedDoc.save("Output.docx")
static class CustomAiModel extends OpenAiModel
{
protected String getUrl() { return "https://your-server.com/v1"; }
protected String getName() { return "my-model-24b"; }
}
我們在Maven存儲庫中託管我們的 Java 'Aspose.Words for Java' 是一個常見的包含字節碼的 JAR 請按照有關如何將其安裝到 Java 開發人員環境的分步說明進行操作。
Java SE 7 和更新的 Java 版本。 Java SE 6 提供了一個單獨的包,以防您不得不使用這個過時的 JRE 。
我們的 Java 包是跨平台的,可以在所有具有 JVM 實現的 Microsoft Windows 、Linux、macOS、Android 和 iOS。
有關可選包依賴項的信息,例如 JogAmp JOGL 、 Harfbuzz 字體引擎、 Java Advanced Imaging JAI ,請參閱產品文檔。