使用 Aspose.Words for C++ 結合 Google Gemini AI 模型來自動化文件翻譯。將 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 檔案翻譯成超過 300 種語言,同時保留原始版面配置與格式。AI 引擎會自動偵測來源語言——即使是在多語言文件中——並且只保留無法識別的片段不予翻譯。
驗證需要 Google API 金鑰。如需支援的 AI 模型完整列表,請參閱 API 參考文件。
立即開始在 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 開源包)的信息。