Method: projects.locations.translateDocument

以同步模式翻譯文件。

HTTP 要求

POST https://{TRANSLATION_GDC_ENDPOINT}/v3/{parent}:translateDocument

路徑參數

參數
parent

string

這是必要旗標,撥打區域電話的位置。

格式:projects/{project-number-or-id}/locations/{location-id}

如需全域呼叫,請使用 projects/{project-number-or-id}/locations/globalprojects/{project-number-or-id}

使用 AutoML 模型或自訂詞彙表的要求必須指定非全域位置。

模型和字彙表必須位於相同區域 (具有相同的 location-id),否則會傳回 INVALID_ARGUMENT (400) 錯誤。

要求主體

要求主體包含下列結構的資料:

JSON 表示法
{
  "sourceLanguageCode": string,
  "targetLanguageCode": string,
  "documentInputConfig": {
    object (DocumentInputConfig)
  },
  "glossaryConfig": {
    object (TranslateTextGlossaryConfig)
  }
}
欄位
sourceLanguageCode

string

(選用步驟) 輸入文件的 ISO-639 語言代碼 (如已知),例如「en-US」或「sr-Latn」。如要查看支援的語言代碼,請參閱「語言支援」。如果未指定原文語言,API 會嘗試自動識別原文語言,並在回應中傳回原文語言。如果要求包含字彙表或自訂模型,則必須指定原文語言。

targetLanguageCode

string

這是必要旗標,用於翻譯輸入文件的 ISO-639 語言代碼,請設為「語言支援」中列出的其中一個語言代碼。

documentInputConfig

object (DocumentInputConfig)

這是必要旗標,輸入設定。

glossaryConfig

object (TranslateTextGlossaryConfig)

(選用步驟) 要套用的詞彙表。字彙表必須與模型位於相同區域 (具有相同的 location-id),否則系統會傳回 INVALID_ARGUMENT (400) 錯誤。

授權需要指定資源 glossaryConfig 的下列 IAM 權限:

  • cloudtranslate.glossaries.docPredict

回應主體

翻譯文件的回覆訊息。

如果成功,回應主體會含有以下結構的資料:

JSON 表示法
{
  "documentTranslation": {
    object (DocumentTranslation)
  },
  "glossaryDocumentTranslation": {
    object (DocumentTranslation)
  },
  "glossaryConfig": {
    object (TranslateTextGlossaryConfig)
  }
}
欄位
documentTranslation

object (DocumentTranslation)

翻譯文件。

glossaryDocumentTranslation

object (DocumentTranslation)

如果要求中提供字彙表,則為文件的翻譯輸出內容。如果沒有套用任何字彙表字詞,這項內容可能與 [TranslateDocumentResponse.document_translation] 相同。

glossaryConfig

object (TranslateTextGlossaryConfig)

用於這項翻譯的 glossaryConfig

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/cloud-translation
  • https://www.googleapis.com/auth/cloud-platform

DocumentInputConfig

文件翻譯要求輸入設定。

JSON 表示法
{
  "mimeType": string,
  "content": string,
  "S3Source": {
    object (S3Source)
  }
}
欄位
mimeType

string

指定輸入文件的 mimeType。

如未指定,系統會使用 S3Source 提供的檔案副檔名判斷類型。如果是透過位元組內容提供的檔案,則必須提供 mimeType。

目前支援的 MIME 類型包括:

  • 應用程式/pdf
  • 應用程式/msword
  • application/vnd.openxmlformats-officedocument.wordprocessingml.document
  • 應用程式/vnd.ms-powerpoint
  • application/vnd.openxmlformats-officedocument.presentationml.presentation
  • 應用程式/vnd.ms-excel
  • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet

支援的檔案格式如下:

  • PDF
  • DOC
  • DOCX
  • PPT
  • PPTX
  • XLS
  • XLSX

content

string (bytes format)

以位元組串流表示的文件內容。

Base64 編碼字串。

S3Source

object (S3Source)

輸入內容的儲存位置。

DocumentTranslation

翻譯過的文件訊息。

JSON 表示法
{
  "byteStreamOutputs": [
    string
  ],
  "mimeType": string,
  "detectedLanguageCode": string
}
欄位
byteStreamOutputs[]

string (bytes format)

翻譯後的文件陣列。目前預計為大小 1。日後我們可能會為其他類型的檔案格式製作多個翻譯文件。

Base64 編碼字串。

mimeType

string

翻譯後文件的 MIME 類型。

detectedLanguageCode

string

輸入文件的偵測語言。如果使用者未提供輸入文件的來源語言,這個欄位會自動偵測語言代碼。如果已傳遞來源語言,系統就不會自動偵測語言,這個欄位也會空白。