Quickstart (Basic)

This page shows how to make a Cloud Translation - Basic (v2) request with curl.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. Set up a Cloud Console project.

    Set up a project

    Click to:

    • Create or select a project.
    • Enable the Cloud Translation API for that project.
    • Create a service account.
    • Download a private key as JSON.

    You can view and manage these resources at any time in the Cloud Console.

  3. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

  4. Install and initialize the Cloud SDK.

Make a Translation API request

Make a Translation API Request using a REST method call to the v2 translate method.

  1. Use curl to make a request to the https://translation.googleapis.com/language/translate/v2 endpoint.

    The curl command includes JSON with the text to be translated (q), the language to translate from (source), and the language to translate to (target).

    The source and target languages are identified using the ISO-639-1 codes. The source language is English (en) and the target language is Spanish (es). The format of the query is noted as "text" for plain text.

    The sample curl command uses the gcloud auth application-default print-access-token command to get an authentication token.

    curl -s -X POST -H "Content-Type: application/json" \
        -H "Authorization: Bearer "$(gcloud auth application-default print-access-token) \
        --data "{
      'q': 'The Great Pyramid of Giza (also known as the Pyramid of Khufu or the
            Pyramid of Cheops) is the oldest and largest of the three pyramids in
            the Giza pyramid complex.',
      'source': 'en',
      'target': 'es',
      'format': 'text'
    }" "https://translation.googleapis.com/language/translate/v2"

    You should see a response similar to the following:

      "data": {
        "translations": [
            "translatedText": "La Gran Pirámide de Giza (también conocida como la
             Pirámide de Khufu o la Pirámide de Keops) es la más antigua y más
             grande de las tres pirámides en el complejo de la pirámide de Giza."

Congratulations! You've sent your first request to the Cloud Translation API!

Install the Cloud Translation - Basic client library

The client libraries are available for several popular languages, and these are the recommended option. To install a client library:


nuget install Google.Cloud.Translation.V2


go get -u cloud.google.com/go/translate


If you are using Maven, add the following to your pom.xml file. For more information about BOMs, see The Google Cloud Platform Libraries BOM.



If you are using Gradle, add the following to your dependencies:

compile 'com.google.cloud:google-cloud-translate:1.95.0'

If you are using sbt, add the following to your dependencies:

libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "1.95.0"

If you're using IntelliJ or Eclipse, you can add client libraries to your project using the following IDE plugins:

The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.


For more on setting up your Node.js development environment, refer to the Node.js Development Environment Setup Guide.

npm install --save @google-cloud/translate


composer require google/cloud-translate


For more on setting up your Python development environment, refer to the Python Development Environment Setup Guide.

pip install google-cloud-translate==2.0.1


For more on setting up your Ruby development environment, refer to the Ruby Development Environment Setup Guide.

gem install google-cloud-translate

Go to Translation Client Libraries for installation instructions.

Clean up

To avoid unnecessary Google Cloud charges, use the Cloud Console to delete your project if you do not need it.

What's next