跳至主要內容

翻譯文件

上傳 DOCX、PPTX、PDF 或 TXT 檔案,查看其狀態,並下載保留原始版面的翻譯檔案。

Markdown

VibeQL 可翻譯 DOCX、PPTX、PDF 和 TXT 檔案。翻譯後的檔案格式與原始檔案相同,且版面維持不變。

翻譯檔案有兩種方式:

  • DeepL 格式。上傳、查看狀態、下載。適合大型檔案,也可搭配 DeepL 用戶端程式庫使用。
  • Azure 格式。以單一請求等待結果,最多 90 秒。適合小型檔案。

DeepL 格式

1. 上傳檔案

POST https://vibeql.com/v2/document 使用 multipart 表單。

欄位 必填 說明
file 有 要翻譯的檔案。
target_lang 有 目標語言代碼,例如 DE 或 PT-BR。
source_lang 不支援 來源語言代碼。留空則從文字中偵測。
filename 不支援 要使用的檔案名稱,取代上傳檔案的名稱。副檔名決定格式。
curl https://vibeql.com/v2/document \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -F "file=@annual-report.pdf" \
  -F "target_lang=PT-BR"
{
  "document_id": "6DCB64C24BB8F7489283D26C42ABDB80",
  "document_key": "D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED"
}

請保留這兩個值。之後針對這份文件提出的每項請求都需要 document_key。

2. 檢查狀態

POST https://vibeql.com/v2/document/{document_id} 在要求主體中帶上 document_key。

curl https://vibeql.com/v2/document/6DCB64C24BB8F7489283D26C42ABDB80 \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -d "document_key=D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED"
status 意義 額外欄位
queued 檔案正在等待翻譯工作節點。 –
translating 翻譯正在進行。 seconds_remaining,預估時間
done 翻譯後的檔案已就緒。 billed_characters
error 翻譯失敗。 error_message
{ "document_id": "6DCB64C24BB8F7489283D26C42ABDB80", "status": "translating", "seconds_remaining": 12 }
{ "document_id": "6DCB64C24BB8F7489283D26C42ABDB80", "status": "done", "billed_characters": 18452 }

每隔幾秒查詢一次,直到狀態為 done 或 error。檔案較大時,請拉長查詢間隔。

3. 下載結果

POST https://vibeql.com/v2/document/{document_id}/result 在要求主體中帶上 document_key。回應內容就是檔案。

curl https://vibeql.com/v2/document/6DCB64C24BB8F7489283D26C42ABDB80/result \
  -H "Authorization: DeepL-Auth-Key $VIBEQL_API_KEY" \
  -d "document_key=D097D7505E5240652F0B5BE2663A212EAA3D79F5C0013AB6051288601405CDED" \
  -o annual-report.pt-BR.pdf

如果翻譯尚未完成,API 會傳回 503 與 {"message": "Document not ready"}。請再次檢查狀態並重試。

程式碼中的完整步驟

DeepL 用戶端程式庫會在一次呼叫中完成上傳、輪詢與下載。請依快速入門的說明設定伺服器 URL。

import os
import deepl

client = deepl.DeepLClient(os.environ["VIBEQL_API_KEY"], server_url="https://vibeql.com")
client.translate_document_from_filepath(
    "annual-report.pdf", "annual-report.pt-BR.pdf", target_lang="PT-BR"
)
import * as deepl from "deepl-node";

const client = new deepl.DeepLClient(process.env.VIBEQL_API_KEY, { serverUrl: "https://vibeql.com" });
await client.translateDocument("annual-report.pdf", "annual-report.pt-BR.pdf", null, "pt-BR");
import os
import time
import requests

BASE = "https://vibeql.com"
HEADERS = {"Authorization": f"DeepL-Auth-Key {os.environ['VIBEQL_API_KEY']}"}

with open("annual-report.pdf", "rb") as f:
    r = requests.post(f"{BASE}/v2/document", headers=HEADERS,
                      files={"file": f}, data={"target_lang": "PT-BR"})
r.raise_for_status()
doc = r.json()

delay = 2
while True:
    s = requests.post(f"{BASE}/v2/document/{doc['document_id']}", headers=HEADERS,
                      data={"document_key": doc["document_key"]}).json()
    if s["status"] == "done":
        break
    if s["status"] == "error":
        raise RuntimeError(s["error_message"])
    time.sleep(delay)
    delay = min(delay * 1.5, 30)

out = requests.post(f"{BASE}/v2/document/{doc['document_id']}/result", headers=HEADERS,
                    data={"document_key": doc["document_key"]})
out.raise_for_status()
with open("annual-report.pt-BR.pdf", "wb") as f:
    f.write(out.content)

Azure 格式

POST https://vibeql.com/translator/document:translate 可在一次請求中翻譯檔案。請以 multipart 欄位 document 傳送檔案。

查詢參數 必填 說明
api-version 有 必須是 2024-05-01。
targetLanguage 有 目標語言,例如 de 或 pt-BR。
sourceLanguage 不支援 來源語言。留空則自動偵測。
curl "https://vibeql.com/translator/document:translate?targetLanguage=de&api-version=2024-05-01" \
  -H "Ocp-Apim-Subscription-Key: $VIBEQL_API_KEY" \
  -F "document=@slides.pptx" \
  -o slides.de.pptx

請求最多等待 90 秒並傳回翻譯後的檔案。若翻譯失敗,會傳回 422。若超過 90 秒,會傳回 504。處理大型檔案時,請改用 DeepL 格式。

格式與限制

格式 副檔名
Word .docx
PowerPoint .pptx
PDF .pdf
純文字 .txt

您的方案決定檔案大小與頁數上限。Beta 帳戶可上傳最大 20 MB、300 頁的檔案。檔案更大會傳回 413。其他檔案類型會傳回 400。請參閱限制與錯誤。

每份文件不收取最低費用。文件會依來源文字的字元數計費,與文字請求相同。狀態為 done 時,billed_characters 欄位會顯示字元數。

保留的內容

  • 頁面與投影片版面。
  • 字型與色彩。PDF 例外,請見下文。
  • 表格與欄位。
  • 圖片,位置保持不變。

已知限制

  • 掃描式 PDF 目前尚未支援翻譯。PDF 必須含有可選取的文字。
  • 圖片中的文字不會翻譯。
  • 在 PDF 中,字型會替換為相同字寬的字型,因此文字會保持原來的大小與位置。
  • WordArt 與內嵌的 OLE 物件不會翻譯。

保留期限

VibeQL 會在上傳後 24 小時刪除原始檔案與翻譯後的檔案。之後的下載請求會傳回 404。請在此之前下載結果。