Tutorials

Google Cloud Translation API: Setup Guide

Updated 2026-03-10

Google Cloud Translation API: Setup Guide

Google Cloud Translation is one of the most widely used translation APIs, supporting 130+ languages with a 500K characters/month free tier. This guide walks you through the complete setup process.

Translation comparisons are based on automated metrics and editorial evaluation. Quality varies by language pair and content type.

Choose Your API Version

Google offers two versions:

FeatureBasic (v2)Advanced (v3)
Price$20/1M chars$80/1M chars
Free tier500K chars/monthNo free tier
Languages130+130+
GlossaryNoYes
Custom models (AutoML)NoYes
Batch translationNoYes
Adaptive TranslationNoYes
Model selectionNoYes

Recommendation: Start with Basic (v2) for most use cases. Upgrade to Advanced (v3) when you need glossary support, batch translation, or custom models.

Step 1: Create a Google Cloud Project

  1. Go to Google Cloud Console
  2. Click “Select a project” in the top bar, then “New Project”
  3. Name your project and click “Create”
  4. Note your project ID (you will need it for API calls)

Step 2: Enable the Translation API

  1. In the Cloud Console, go to “APIs & Services” > “Library”
  2. Search for “Cloud Translation API”
  3. Click “Enable”

Step 3: Create API Credentials

Option A: API Key (simplest)

  1. Go to “APIs & Services” > “Credentials”
  2. Click “Create Credentials” > “API Key”
  3. Copy and securely store your API key
  4. Recommended: Restrict the key to the Translation API only
  1. Go to “APIs & Services” > “Credentials”
  2. Click “Create Credentials” > “Service Account”
  3. Name it and grant the “Cloud Translation API User” role
  4. Create a JSON key and download it
  5. Set the environment variable: export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"

Step 4: Make Your First API Call

Using curl (Basic v2)

curl -X POST \
  "https://translation.googleapis.com/language/translate/v2?key=YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "Hello, world!", "target": "es"}'

Using Python (Basic v2)

import requests

API_KEY = "YOUR_API_KEY"
url = f"https://translation.googleapis.com/language/translate/v2?key={API_KEY}"

response = requests.post(url, json={
    "q": "Hello, how are you?",
    "target": "es",
    "source": "en"
})

result = response.json()
print(result["data"]["translations"][0]["translatedText"])
# "Hola, ¿cómo estás?"

Using Python SDK (Advanced v3)

from google.cloud import translate_v3 as translate

client = translate.TranslationServiceClient()
project_id = "your-project-id"
parent = f"projects/{project_id}/locations/global"

response = client.translate_text(
    request={
        "parent": parent,
        "contents": ["Hello, how are you?"],
        "mime_type": "text/plain",
        "source_language_code": "en",
        "target_language_code": "es",
    }
)

for translation in response.translations:
    print(translation.translated_text)

Install the SDK: pip install google-cloud-translate

Step 5: Language Detection

Google can auto-detect the source language:

response = requests.post(url, json={
    "q": "Bonjour le monde",
    "target": "en"
    # No "source" field — auto-detection
})

result = response.json()
detected = result["data"]["translations"][0]["detectedSourceLanguage"]
print(f"Detected: {detected}")  # "fr"

Step 6: Set Up Glossary (v3 Only)

Glossaries enforce consistent terminology translation:

from google.cloud import translate_v3 as translate

client = translate.TranslationServiceClient()
parent = f"projects/{project_id}/locations/us-central1"

glossary_id = "my-glossary"
glossary = translate.Glossary(
    name=f"{parent}/glossaries/{glossary_id}",
    language_pair=translate.Glossary.LanguageCodePair(
        source_language_code="en",
        target_language_code="es"
    ),
    input_config=translate.GlossaryInputConfig(
        gcs_source=translate.GcsSource(
            input_uri="gs://your-bucket/glossary.csv"
        )
    )
)

operation = client.create_glossary(parent=parent, glossary=glossary)
result = operation.result()

Glossary CSV format:

en,es
API key,clave de API
repository,repositorio
deploy,desplegar

Cost Management

Set Budget Alerts

  1. Go to “Billing” > “Budgets & alerts”
  2. Create a budget for your project
  3. Set threshold alerts (e.g., 50%, 75%, 100% of budget)

Monitor Usage

  1. Go to “APIs & Services” > “Dashboard”
  2. Select “Cloud Translation API”
  3. View request counts and character counts

Set Quotas

  1. Go to “APIs & Services” > “Quotas”
  2. Search for Translation API quotas
  3. Set per-minute and per-day limits to prevent runaway costs

Translation API Pricing Calculator

Common Patterns

Batch Translation (v3)

For translating large volumes, use batch translation to process files asynchronously:

operation = client.batch_translate_text(
    request={
        "parent": parent,
        "source_language_code": "en",
        "target_language_codes": ["es", "fr", "de"],
        "input_configs": [{"gcs_source": {"input_uri": "gs://bucket/input.txt"}}],
        "output_config": {"gcs_destination": {"output_uri_prefix": "gs://bucket/output/"}}
    }
)

HTML Translation

Preserve HTML tags while translating content:

response = requests.post(url, json={
    "q": "<p>Hello <strong>world</strong></p>",
    "target": "es",
    "format": "html"
})
# Returns: "<p>Hola <strong>mundo</strong></p>"

Key Takeaways

  • Google Cloud Translation is straightforward to set up and offers a generous 500K character/month free tier on the Basic API.
  • Start with the Basic (v2) API and API key authentication for simplicity. Upgrade to Advanced (v3) when you need glossaries, batch translation, or custom models.
  • Always set budget alerts and quotas to prevent unexpected charges.
  • The glossary feature (v3 only) is essential for maintaining terminology consistency in professional translation.

Next Steps