Quickstart: Setup (Advanced)

Before you begin

Translation is available in two editions. This guide provides all required setup steps to start using Cloud Translation - Advanced.

GCP Console

The Google Cloud Console is a web UI used to provision, configure, manage, and monitor systems that use Google Cloud products. You use the Google Cloud Console to set up and manage Cloud Translation resources.

Create 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. For more information on projects, see the Resource Manager documentation.

If you plan on using your project for more than just basic access to Cloud Translation - Basic, or you plan on using the API, you should create a project with the Google Cloud Console as described below.

You should create separate projects for experiments, testing, and production. When creating a project, take note of the project number or ID. You must provide the project number (or ID) when making calls to the Cloud Translation API.

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

Go to the project selector page

Enable billing

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.

Steps for enabling billing

  1. Go to the Google Cloud Console.
  2. Navigate to the drop-down menu at the top of the page and choose the Google Cloud project that you'd like to associate with Cloud Translation. If you have previously created one or more projects, they appear in a list in the pop-up menu. You can either choose a pre-existing project (a check mark appears next to the project you select) or create a new project by clicking New Project. For more details on creating a Google Cloud project, see Creating and Managing Projects.

    New Project dialog in Google Cloud Console.

  3. Select/verify billing account billing account.

    • If you create a new project, you are prompted to link a billing account for this project.
    • If you are using a pre-existing project, make sure that you have billing enabled. You can access the project's billing information at any time by going to the main navigation menu () and clicking the Billing option.

Enable the API

To enable Translation, you must accept the Data Logging Terms & Conditions.

  1. Go to the main navigation menu () in the GCP Console.

  2. Scroll down to the Artificial Intelligence section and select Translation.

  3. Click Overview from the menu that pops up.

Enabling the API

To enable the Cloud Translation - Advanced for use with your Google Cloud project, click Enable. The data logging page appears. You must accept the terms & conditions to have full access to Cloud Translation - Advanced features. Click Enable.

Trying this API

If you would first like to try the API without linking it to your project, choose the Try this API option.

Set up authentication

Once you've enabled data logging, you are prompted to link one or more service accounts to the Cloud Translation API. If you plan to use the Translation, you must 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 up authentication. For more information, see the Google Cloud authentication overview.

Service accounts

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 Service accounts.

Roles

When the API is called, Google Cloud requires that the caller has the appropriate permissions. You can grant permissions by granting roles to a service account. For example, if you want to use your service account to translate text, you would assign the roles/cloudtranslate.user role to it. For the purpose of trying the Cloud Translation API, you can use the Project > Editor role in steps below, which grants the service account full access to the project. See IAM permissions for full details on the available roles and the permissions allowed for each role.

For more information on understanding roles, see the Cloud Identity and Access Management documentation.

Service account keys

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.

Create a service account and download the private key file

Set up authentication:
  1. In the Cloud Console, go to the Create service account key page.

    Go to the Create Service Account Key page
  2. From the Service account list, select New service account.
  3. In the Service account name field, enter a name.
  4. From the Role list, select Project > Owner.

    Note: The Role field authorizes your service account to access resources. You can view and change this field later by using the Cloud Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
  5. Click Create. A JSON file that contains your key downloads to your computer.

Use the service account key file in your environment

Provide authentication credentials to your application code by setting the environment variable GOOGLE_APPLICATION_CREDENTIALS. Replace [PATH] with the file path of the JSON file that contains your service account key, and [FILE_NAME] with the filename. This variable only applies to your current shell session, so if you open a new session, set the variable again.

Linux or macOS

export GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

For example:

export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/[FILE_NAME].json"

Windows

With PowerShell:

$env:GOOGLE_APPLICATION_CREDENTIALS="[PATH]"

For example:

$env:GOOGLE_APPLICATION_CREDENTIALS="C:\Users\username\Downloads\[FILE_NAME].json"

With command prompt:

set GOOGLE_APPLICATION_CREDENTIALS=[PATH]

Install and initialize the Cloud SDK

If you plan to use the Translation, you need to install and initialize the Cloud SDK. Cloud SDK is a set of tools that you can use to manage resources and applications hosted on Google Cloud. This includes the gcloud command line tool. The following link provides instructions:

Install and initialize the Cloud SDK.

Test the SDK and authentication

If you have set up authentication in previous steps, you can use the gcloud tool to test your authentication environment. Execute the following command and verify that no error occurs and that credentials are returned:

gcloud auth application-default print-access-token

That command is used by all Cloud Translation - Advanced command line REST samples to authenticate API calls.

Install the Cloud Translation - Advanced client library

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

C#

nuget install Google.Cloud.Translate.V3 -Pre

Go

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

Java

If you are using Maven, add the following to your pom.xml file:
<dependencyManagement>
 <dependencies>
  <dependency>
    <groupId>com.google.cloud</groupId>
    <artifactId>libraries-bom</artifactId>
    <version>2.8.0</version>
    <type>pom</type>
    <scope>import</scope>
   </dependency>
 </dependencies>
</dependencyManagement>

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-translate</artifactId>
</dependency>
If you are using Gradle, add the following to your dependencies:
compile 'com.google.cloud:google-cloud-translate:1.94.1'
If you are using SBT, add the following to your dependencies:
libraryDependencies += "com.google.cloud" % "google-cloud-translate" % "1.94.1"

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.

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 install 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

Go to Translation Client Libraries for installation instructions for each supported language.

Clean up

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

What's next

Оцените, насколько информация на этой странице была вам полезна:

Оставить отзыв о...

Текущей странице
Cloud Translation
Нужна помощь? Обратитесь в службу поддержки.