Specify a regional endpoint

Cloud Translation - Advanced offers an EU regional API endpoint. If you use the regional endpoint, your data at-rest stays within the continental boundaries of the EU. Specifying an endpoint is important if your data's location must be controlled to comply with local regulatory requirements. The Cloud Translation - Advanced EU regional API endpoint is translate-eu.googleapis.com

There are some differences when using the EU regional API endpoint compared to using the global endpoint (translate.googleapis.com):

  • Text translations that use custom AutoML models are not supported. You can use only the pre-trained NMT model.
  • Batch translations are not supported.
  • Features that are not GA (still in Preview) are not supported, such as Document Translation.
  • Calls through the global endpoint cannot access resources that were created by using the EU endpoint, which have a location of europe-west1. Similarly, calls through the EU endpoint cannot access resources that were created by using the global endpoint.

Restricting resource locations

Organization policy administrators can restrict the regions available for Cloud Translation - Advanced resources by creating a resource locations constraint.

Example usage

The following example shows a text translation that uses a regional endpoint. If you use the client libraries, set the API endpoint as part of the client options. For some examples, see Setting the location using client libraries in the Cloud Natural Language API guide.

REST & CMD LINE

Before using any of the request data, make the following replacements:

  • PROJECT_NUMBER_OR_ID: Your Google Cloud project number or ID
  • ENDPOINT: Regional endpoint, which determines where your data resides. For example, translate-eu.googleapis.com.
  • LOCATION: Region where you want to run this operation. You must pick a region inside the continental boundary of the regional endpoint. For example, if you use the translate-eu.googleapis.com endpoint, specify a region in Europe such as europe-west1.

HTTP method and URL:

POST https://ENDPOINT/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION:translateText

Request JSON body:

{
  "model": "projects/PROJECT_NUMBER_OR_ID/locations/LOCATION/models/general/base",
  "sourceLanguageCode": "en",
  "targetLanguageCode": "de",
  "contents": ["Come here!"]
}

To send your request, choose one of these options:

curl

Save the request body in a file called request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://ENDPOINT/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION:translateText "

PowerShell

Save the request body in a file called request.json, and execute the following command:

$cred = gcloud auth application-default print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://ENDPOINT/v3/projects/PROJECT_NUMBER_OR_ID/locations/LOCATION:translateText " | Select-Object -Expand Content

You should receive a JSON response similar to the following:

{
  "translations": [
    {
      "translatedText": "Komm her!",
      "model": "projects/PROJECT_NUMBER_OR_ID/locations/LOCATION/models/general/base"
    }
  ]
}