Codelab-at-a-conference setup

The instructor will be sharing with you temporary accounts with existing projects that are already setup so you do not need to worry about enabling billing or any cost associated with running this codelab. Note that all these accounts will be disabled soon after the codelab is over.

If the API is already enabled, you will see a "Disable" button. Do not disable the API.

If the API is disabled, Click Enable to enable the Cloud Translation API:

Wait for a few seconds for it to enable. You will see this once it's enabled:

Google Cloud Shell is a command line environment running in the Cloud. This Debian-based virtual machine is loaded with all the development tools you'll need (gcloud, bq, git and others) and offers a persistent 5GB home directory. We'll use Cloud Shell to create our request to the Translation API.

To get started with Cloud Shell, Click on the "Activate Google Cloud Shell" icon in top right hand corner of the header bar

A Cloud Shell session opens inside a new frame at the bottom of the console and displays a command-line prompt. Wait until the user@project:~$ prompt appears

Since we'll be using curl to send a request to the Translation API, we'll need to generate an API key to pass in our request URL. To create an API key, navigate to the API Manager section of your project dashboard:

Then, navigate to the Credentials tab and click Create credentials:

In the drop down menu, select API key:

Next, copy the key you just generated.

Copy your API Key to your clipboard then save it to an environment variable in Cloud Shell using the following line of code. Be sure to replace YOUR_API_KEY with the key from your clipboard.

export API_KEY=YOUR_API_KEY

In this example you will translate the string "My name is Steve" into Spanish. Pass the text to be translated, along with the API key environment variable you saved earlier, to the Translation API with the following curl command:

In the response, you can see that the translated text as well as the source language that the API detected.​

Premium Model

Note that the Google Cloud Translation API uses a standard edition model for most translation tasks. Google has augmented its translation service to use a more robust Neural machine Translation System. You can utilize this premium model. See this guide for more information.

In addition to translating text, the Translation API also lets you detect the language of text. In this example you will detect the language of two strings. Pass the text to be examined, along with the API key environment variable you saved earlier, to the Translation API with the following curl command: