使用 Google Gemini AI 模型和 Aspose.Words for Java 自动化文档翻译。将 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 文件翻译成 300 多种语言,同时保留原始布局和格式。基于 AI 的引擎会自动检测源语言——即使在多语言文档中——并仅对无法识别的片段保持未翻译状态。
身份验证需要 Google API 密钥。有关支持的 AI 模型完整列表,请参阅 API Reference。
立即在 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 ,请参阅产品文档。