Method: projects.locations.translateText

Translates input text and returns translated text.

HTTP request

POST https://translation.googleapis.com/v3beta1/{parent=projects/*/locations/*}:translateText

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
parent

string

Required. Location to make a regional or global call.

Format: projects/{project-id}/locations/{location-id}.

For global calls, use projects/{project-id}/locations/global.

Models and glossaries must be within the same region (have same location-id), otherwise an INVALID_ARGUMENT (400) error is returned.

Request body

The request body contains data with the following structure:

JSON representation
{
  "contents": [
    string
  ],
  "mimeType": string,
  "sourceLanguageCode": string,
  "targetLanguageCode": string,
  "model": string,
  "glossaryConfig": {
    object (TranslateTextGlossaryConfig)
  }
}
Fields
contents[]

string

Required. The content of the input in string format. We recommend the total content be less than 30k codepoints. Use locations.batchTranslateText for larger text.

mimeType

string

Optional. The format of the source text, for example, "text/html", "text/plain". If left blank, the MIME type defaults to "text/html".

sourceLanguageCode

string

Optional. The BCP-47 language code of the input text if known, for example, "en-US" or "sr-Latn". Supported language codes are listed in Language Support. If the source language isn't specified, the API attempts to identify the source language automatically and returns the source language within the response.

targetLanguageCode

string

Required. The BCP-47 language code to use for translation of the input text, set to one of the language codes listed in Language Support.

model

string

Optional. The model type requested for this translation.

The format depends on model type:

  • AutoML Translation models: projects/{project-id}/locations/{location-id}/models/{model-id}

  • General (built-in) models: projects/{project-id}/locations/{location-id}/models/general/nmt, projects/{project-id}/locations/{location-id}/models/general/base

For global (non-regionalized) requests, use location-id global. For example, projects/{project-id}/locations/global/models/general/nmt.

If missing, the system decides which google base model to use.

Authorization requires one or more of the following Google IAM permissions on the specified resource model:

  • cloudtranslate.generalModels.predict
  • automl.models.predict

glossaryConfig

object (TranslateTextGlossaryConfig)

Optional. Glossary to be applied. The glossary must be within the same region (have the same location-id) as the model, otherwise an INVALID_ARGUMENT (400) error is returned.

Authorization requires the following Google IAM permission on the specified resource glossaryConfig:

  • cloudtranslate.glossaries.predict

Response body

If successful, the response body contains data with the following structure:

JSON representation
{
  "translations": [
    {
      object (Translation)
    }
  ],
  "glossaryTranslations": [
    {
      object (Translation)
    }
  ]
}
Fields
translations[]

object (Translation)

Text translation responses with no glossary applied. This field has the same length as contents.

glossaryTranslations[]

object (Translation)

Text translation responses if a glossary is provided in the request. This can be the same as translations if no terms apply. This field has the same length as contents.

Authorization Scopes

Requires one of the following OAuth scopes:

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

For more information, see the Authentication Overview.

TranslateTextGlossaryConfig

Configures which glossary should be used for a specific target language, and defines options for applying that glossary.

JSON representation
{
  "glossary": string,
  "ignoreCase": boolean
}
Fields
glossary

string

Required. Specifies the glossary used for this translation. Use this format: projects/*/locations/*/glossaries/*

ignoreCase

boolean

Optional. Indicates match is case-insensitive. Default value is false if missing.

Translation

A single translation response.

JSON representation
{
  "translatedText": string,
  "model": string,
  "detectedLanguageCode": string,
  "glossaryConfig": {
    object (TranslateTextGlossaryConfig)
  }
}
Fields
translatedText

string

Text translated into the target language.

model

string

Only present when model is present in the request. This is same as model provided in the request.

detectedLanguageCode

string

The BCP-47 language code of source text in the initial request, detected automatically, if no source language was passed within the initial request. If the source language was passed, auto-detection of the language does not occur and this field is empty.

glossaryConfig

object (TranslateTextGlossaryConfig)

The glossaryConfig used for this translation.

หน้านี้มีประโยชน์ไหม โปรดแสดงความคิดเห็น

ส่งความคิดเห็นเกี่ยวกับ...

หากต้องการความช่วยเหลือ ให้ไปที่หน้าการสนับสนุน