在 C++ 中翻譯 Word、PDF、Web 文件

使用 AI 翻譯文件的 C++ 解決方案

與 Google Gemini 生成式語言模型的無縫整合,為 C++ 應用程式提供廣泛的 AI 文件處理功能。

查看代碼片段

在 C++ 中將文件翻譯為 300+ 種語言

使用 Aspose.Words for C++ 結合 Google Gemini AI 模型來自動化文件翻譯。將 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 和 EPUB 檔案翻譯成超過 300 種語言,同時保留原始版面配置與格式。AI 引擎會自動偵測來源語言——即使是在多語言文件中——並且只保留無法識別的片段不予翻譯。

為什麼開發者選擇 Aspose.Words 進行文件翻譯

  • 只需單一 API 呼叫即可翻譯整份文件
  • 自動偵測混合語言文件的來源語言
  • 輸出結果保留原始格式與版面配置
  • 支援 DOC、DOCX、RTF、PDF、ODT、HTML、Markdown、TXT、EPUB 等多種格式

驗證需要 Google API 金鑰。如需支援的 AI 模型完整列表,請參閱 API 參考文件

立即開始在 C++ 中翻譯文件——試試上方的即時展示。

在 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; }
};
運行代碼

如何在 C++ 中翻譯文件

  1. 安裝 Aspose.Words for C++。
  2. 將函式庫參考(匯入函式庫)加入您的 C++ 專案。
  3. 在 C++ 中開啟來源檔案。
  4. 呼叫 Translate 方法,傳入您的文件與目標語言。
  5. 完成後,您將取得翻譯好的文件,您可以將其另存為所需格式的新檔案。

C++ 函式庫,用於翻譯文件

有三個選項可以將 Aspose.Words for C++ 安裝到您的開發人員環境中。請選擇符合您需求的一種,並按照分步說明進行操作:

系統要求

您可以使用這個 C++ 庫在 Microsoft Windows 、Linux 和 macOS 操作系統上開發軟件:

  • Linux 需要 GCC >= 6.3.0 和 Clang >= 3.9.1
  • Xcode >= 12.5.1 ,macOS 需要 Clang 和 libc++

如果您為 Linux 或 macOS 開發軟件,請查看產品文檔中 fontconfig 和 mesa-glu 開源包)的信息。

5%

訂閱 Aspose 產品更新

獲取直接發送到您的郵箱的每月通訊和優惠。

© Aspose Pty Ltd 2001-2026. 版權所有。