Setup

To start using Cloud Translation, you need a project that has the Cloud Translation API enabled and credentials to make authenticated calls. The following sections detail how to get set up before you make your first call to the Cloud Translation API.

The setup process involves the Google Cloud console, which is a web interface that you can use to provision, configure, manage, and monitor systems in Google Cloud. If you haven't used the Google Cloud console before, see the Cloud console page for more information.

Before you begin

Cloud Translation is available in two editions (Basic and Advanced). Decide which edition to use because that determines which version of the client libraries to install.

Create or select a project

To use services provided by Google Cloud, you must create a project. A project organizes all your Google Cloud resources. A project consists of a set of collaborators, enabled APIs (and other resources), monitoring tools, billing information, and authentication and access controls. You can create one project, or you can create multiple projects and use them to organize your Google Cloud resources in a resource hierarchy. When creating a project, take note of the project ID. You will need this ID to make API calls. For more information on projects, see the Resource Manager documentation.

We recommend that you create separate projects for experiments, testing, and production. After you create a project, record the project number or ID. You must provide the project number (or ID) when you make calls to the Cloud Translation API.

In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

Go to project selector

Enable billing

You must enable billing to use Cloud Translation. For more information about Cloud Translation pricing, see the pricing page.

A billing account is used to define who pays for a given set of resources, and it can be linked to one or more projects. Project usage is charged to the linked billing account. In most cases, you configure billing when you create a project. For more information, see the Billing documentation.

Make sure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project.

Enabling the API

You must enable the Cloud Translation API for your project. For more information on enabling APIs, see the Service Usage documentation.

Enable the Cloud Translation API.

Enable the API

Set usage quotas

Cloud Translation has a quota management system to help you and Google manage usage of the service. By default, the number of characters that you can send per day is unlimited. If you have a set budget, we recommend monitoring your daily usage and adjusting quotas according to your planned spend.

For more information about quotas, see Quotas and limits.

Set up authentication

If you plan to use the Cloud Translation API, you need to set up authentication. Any client application that uses the API must be authenticated and granted access to the requested resources. This section describes important authentication concepts and provides steps for setting it up. For more information, see the Google Cloud authentication overview.

Service account and private key

There are multiple options for authentication, but it is recommended that you use service accounts for authentication and access control. A service account provides credentials for applications, as opposed to end-users. Service accounts are owned by projects, and you can create many service accounts for a project. For more information, see Understanding service accounts.

Service accounts are associated with one or more public/private key pairs. When you create a new key pair, you download the private key. Your private key is used to generate credentials when calling the API. You are responsible for security of the private key and other management operations, such as key rotation. For more information, see Best practices for managing service account keys.

Identity and Access Management roles

When a principal (user account, service account, and so on) calls an API, Google Cloud requires that the principal has the appropriate permissions. You can grant permissions by granting roles to a principal. For more information, see the role overview.

If you have created your project with your user account, your user account has the Owner basic role for the project. This role provides access to call any API for the project. However, if a different account created the project, you may need to have roles granted to your user account before you can call the API.

Creating service accounts and keys

Create a service account:

  1. In the Google Cloud console, go to the Create service account page.

    Go to Create service account
  2. Select your project.
  3. In the Service account name field, enter a name. The Google Cloud console fills in the Service account ID field based on this name.

    In the Service account description field, enter a description. For example, Service account for quickstart.

  4. Click Create and continue.
  5. To provide access to your project, grant the Cloud Translation > Cloud Translation API Admin role to your service account.

    To grant the role, find the Select a role list, then select Cloud Translation > Cloud Translation API Admin.

  6. Click Continue.
  7. Click Done to finish creating the service account.

    Do not close your browser window. You will use it in the next step.

Create a service account key:

  1. In the Google Cloud console, click the email address for the service account that you created.
  2. Click Keys.
  3. Click Add key, and then click Create new key.
  4. Click Create. A JSON key file is downloaded to your computer.
  5. Click Close.

For more information about the different roles, see Cloud Translation - Advanced roles. For example, if you want to allow your service account to translate text, assign the roles/cloudtranslate.user role to it. All of the keys that are associated with that service account receive the same permissions.

Using the service account key file in your environment

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. This variable applies only to your current shell session. If you want the variable to apply to future shell sessions, set the variable in your shell startup file, for example in the ~/.bashrc or ~/.profile file.

Linux or macOS

export GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Replace KEY_PATH with the path of the JSON file that contains your service account key.

For example:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

Windows

For PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="KEY_PATH"

Replace KEY_PATH with the path of the JSON file that contains your service account key.

For example:

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\service-account-file.json"

For command prompt:

set GOOGLE_APPLICATION_CREDENTIALS=KEY_PATH

Replace KEY_PATH with the path of the JSON file that contains your service account key.

Alternatively, you can point to the JSON file in your code. For more information, see Passing credentials using code.

Installing client libraries

Client libraries are available for several popular languages. We recommend that you use these client libraries to make calls to Cloud Translation because they make it easier to access the APIs. If a client library doesn't meet your needs or isn't available for your language, build your own custom code. For more information, see Using your own client code.

For example, when you use a client library, it can determine your credentials implicitly through the GOOGLE_APPLICATION_CREDENTIALS environment variable. You don't need to explicitly specify your credentials in code. For more information, see Client Libraries Explained in the Cloud APIs documentation.

Cloud Translation - Basic client libraries

Select the programming language that you are using for development, and then run the related command. For more information, see the Cloud Translation - Basic client libraries overview.

C#

nuget install Google.Cloud.Translation.V2

Go

go get cloud.google.com/go/translate

Java

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.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.12.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-translate</artifactId>
  </dependency>

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

implementation 'com.google.cloud:google-cloud-translate:2.18.0'

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

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

If you're using Visual Studio Code, 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.

Node.js

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

PHP

composer require google/cloud-translate

Python

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

Ruby

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

gem install google-cloud-translate-v2

Cloud Translation - Advanced client libraries

Select the programming language that you are using for development, and then run the related command. For more information, see the Cloud Translation - Advanced client libraries overview.

C#

nuget install Google.Cloud.Translate.V3 -Pre

Go

go get cloud.google.com/go/translate/apiv3

Java

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.

<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>libraries-bom</artifactId>
      <version>26.12.0</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

<dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>google-cloud-translate</artifactId>
  </dependency>

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

implementation 'com.google.cloud:google-cloud-translate:2.18.0'

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

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

If you're using Visual Studio Code, 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.

Node.js

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

PHP

composer require google/cloud-translate

Python

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

pip install --upgrade google-cloud-translate

Ruby

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

gem install google-cloud-translate

Install the Google Cloud CLI

If you plan to send Cloud Translation requests through the command line (such as through curl commands), install and initialize the gcloud CLI , which is included in the Google Cloud CLI. The following link provides more information:

Install the Google Cloud CLI, then initialize it by running the following command:

gcloud init

Test the SDK and authentication

If you have set up the GOOGLE_APPLICATION_CREDENTIALS environment variable, you can use gcloud to test your authentication environment. Run the following command and verify that no error occurs and that credentials are returned:

gcloud auth application-default print-access-token

The previous command is used by all Cloud Translation command line REST samples to authenticate API calls.

What's next

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Cloud Translation performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Cloud Translation free