使用 Google Gemini AI 模型和 Aspose.Words for C++ 自动化文档翻译。将 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 文件翻译成 300 多种语言,同时保留原始布局和格式。基于 AI 的引擎会自动检测源语言——即使在多语言文档中——并仅对无法识别的片段保持未翻译状态。
身份验证需要 Google API 密钥。有关支持的 AI 模型完整列表,请参阅 API Reference。
立即在 C++ 开始翻译文档——尝试上方的实时演示。
dotnet add package Aspose.Words.Cpp
复制
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
auto apiKey = System::Environment::GetEnvironmentVariable(u"API_KEY");
// 使用 Google 生成式语言模型。
System::SharedPtr<Aspose::Words::AI::AiModel> model = Aspose::Words::AI::AiModel::Create(Aspose::Words::AI::AiModelType::GeminiFlashLatest)->WithApiKey(apiKey);
auto translatedDoc = model->Translate(doc, Aspose::Words::AI::Language::Arabic);
translatedDoc->Save(u"Output.docx");
auto doc = System::MakeObject<Aspose::Words::Document>(u"Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
auto model = System::MakeObject<CustomAiModel>(u"my-model-24b", u"https://your-server.com/v1");
model->WithApiKey(u"");
auto translatedDoc = model->Translate(doc, Aspose::Words::AI::Language::Arabic);
translatedDoc->Save(u"Output.docx");
class CustomAiModel : public Aspose::Words::AI::OpenAiModel
{
private:
System::String mUrl;
public:
CustomAiModel(System::String name, System::String url) : OpenAiModel(name) { mUrl = url; }
System::String get_Url() override { return mUrl; }
};
有三个选项可以将 Aspose.Words for C++ 安装到您的开发人员环境中。请选择符合您需求的一种,并按照分步说明进行操作:
您可以使用这个 C++ 库在 Microsoft Windows 、Linux 和 macOS 操作系统上开发软件:
如果您为 Linux 或 macOS 开发软件,请查看产品文档中 fontconfig 和 mesa-glu 开源包)的信息。