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. Target project or location to make a call.

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

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

Non-global location is required for requests using AutoML models or custom glossaries.

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 an instance of TranslateTextResponse.

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.

هل كانت هذه الصفحة مفيدة؟ يرجى تقييم أدائنا:

إرسال تعليقات حول...

هل تحتاج إلى مساعدة؟ انتقل إلى صفحة الدعم.