or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.mdv2-legacy-api.mdv3-adaptive-mt.mdv3-automl-translation.mdv3-data-structures.mdv3-glossary-management.mdv3-request-response-types.mdv3-translation-services.md
tile.json

tessl/pypi-google-cloud-translate

Google Cloud Translate API client library for translating text between thousands of language pairs with support for adaptive MT, AutoML, and glossaries

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/google-cloud-translate@3.21.x

To install, run

npx @tessl/cli install tessl/pypi-google-cloud-translate@3.21.0

index.mddocs/

Google Cloud Translate

A comprehensive Python client library for Google Cloud Translate API, enabling developers to dynamically translate text between thousands of language pairs. The library offers programmatic integration with Google's translation service, supporting both basic text translation and advanced features through multiple API versions (v2, v3, v3beta1).

Package Information

  • Package Name: google-cloud-translate
  • Language: Python
  • Installation: pip install google-cloud-translate

Core Imports

Primary import (provides V3 API by default):

from google.cloud import translate

This gives access to the main TranslationServiceClient and all V3 types:

from google.cloud.translate import TranslationServiceClient, TranslationServiceAsyncClient

For specific API versions:

# V2 API (legacy)
from google.cloud import translate_v2

# V3 API (explicit)
from google.cloud import translate_v3

# V3 Beta API
from google.cloud import translate_v3beta1

Basic Usage

Simple Translation (V3 - Recommended)

from google.cloud import translate

# Create a client (uses V3 by default)
client = translate.TranslationServiceClient()

# Configure the parent resource name
parent = f"projects/{project_id}/locations/{location}"

# Translate text
response = client.translate_text(
    request={
        "parent": parent,
        "contents": ["Hello, world!"],
        "mime_type": "text/plain",
        "source_language_code": "en",
        "target_language_code": "es",
    }
)

for translation in response.translations:
    print(f"Translated text: {translation.translated_text}")

Legacy Translation (V2)

from google.cloud import translate_v2 as translate

client = translate.Client()

# Translate text
result = client.translate(
    "Hello, world!",
    target_language="es",
    source_language="en"
)

print(f"Text: {result['input']}")
print(f"Translation: {result['translatedText']}")
print(f"Detected source language: {result['detectedSourceLanguage']}")

Architecture

The library provides three distinct API versions with different capabilities:

  • V2 API: Legacy REST-based API with simple translation, detection, and language listing functionality
  • V3 API: Full-featured gRPC/REST API with advanced capabilities including adaptive MT, AutoML, glossaries, and document translation
  • V3Beta1 API: Beta version with core translation features and glossary support

Each API version provides both synchronous and asynchronous clients, comprehensive type definitions, transport layer abstractions, and pagination support for list operations.

Capabilities

V2 Legacy API

Simple REST-based translation API with basic functionality including text translation, language detection, and supported language listing.

class Client:
    def get_languages(self, target_language=None): ...
    def detect_language(self, values): ...
    def translate(self, values, target_language=None, format_=None, source_language=None, customization_ids=(), model=None): ...

V2 Legacy API

V3 Translation Services

Core translation functionality including text translation, document translation, batch operations, language detection, and romanization.

class TranslationServiceClient:
    def translate_text(self, request=None, **kwargs): ...
    def translate_document(self, request=None, **kwargs): ...
    def batch_translate_text(self, request=None, **kwargs): ...
    def batch_translate_document(self, request=None, **kwargs): ...
    def detect_language(self, request=None, **kwargs): ...
    def get_supported_languages(self, request=None, **kwargs): ...
    def romanize_text(self, request=None, **kwargs): ...

V3 Translation Services

V3 Adaptive Machine Translation

Advanced machine translation using custom datasets and models trained on domain-specific translation pairs for improved accuracy in specialized contexts.

class TranslationServiceClient:
    def create_adaptive_mt_dataset(self, request=None, **kwargs): ...
    def list_adaptive_mt_datasets(self, request=None, **kwargs): ...
    def get_adaptive_mt_dataset(self, request=None, **kwargs): ...
    def delete_adaptive_mt_dataset(self, request=None, **kwargs): ...
    def adaptive_mt_translate(self, request=None, **kwargs): ...
    def import_adaptive_mt_file(self, request=None, **kwargs): ...
    def list_adaptive_mt_files(self, request=None, **kwargs): ...
    def get_adaptive_mt_file(self, request=None, **kwargs): ...
    def delete_adaptive_mt_file(self, request=None, **kwargs): ...
    def list_adaptive_mt_sentences(self, request=None, **kwargs): ...

V3 Adaptive Machine Translation

V3 Glossary Management

Translation glossaries for consistent terminology translation, including creation, management, and application of custom dictionaries for domain-specific translations.

class TranslationServiceClient:
    def create_glossary(self, request=None, **kwargs): ...
    def update_glossary(self, request=None, **kwargs): ...
    def list_glossaries(self, request=None, **kwargs): ...
    def get_glossary(self, request=None, **kwargs): ...
    def delete_glossary(self, request=None, **kwargs): ...
    def create_glossary_entry(self, request=None, **kwargs): ...
    def update_glossary_entry(self, request=None, **kwargs): ...
    def list_glossary_entries(self, request=None, **kwargs): ...
    def get_glossary_entry(self, request=None, **kwargs): ...
    def delete_glossary_entry(self, request=None, **kwargs): ...

V3 Glossary Management

V3 AutoML Translation

Custom machine learning model training and management for specialized translation needs, including dataset creation, model training, and custom model usage.

class TranslationServiceClient:
    def create_dataset(self, request=None, **kwargs): ...
    def list_datasets(self, request=None, **kwargs): ...
    def get_dataset(self, request=None, **kwargs): ...
    def delete_dataset(self, request=None, **kwargs): ...
    def import_data(self, request=None, **kwargs): ...
    def export_data(self, request=None, **kwargs): ...
    def list_examples(self, request=None, **kwargs): ...
    def create_model(self, request=None, **kwargs): ...
    def list_models(self, request=None, **kwargs): ...
    def get_model(self, request=None, **kwargs): ...
    def delete_model(self, request=None, **kwargs): ...

V3 AutoML Translation

Request and Response Types

Complete type definitions for all request and response objects used across the V3 API, including translation requests, document configurations, and metadata structures.

class TranslateTextRequest: ...
class TranslateTextResponse: ...
class TranslateDocumentRequest: ...
class TranslateDocumentResponse: ...
class DetectLanguageRequest: ...
class DetectLanguageResponse: ...

Request and Response Types

Data Structures and Enums

Core data structures, enums, and configuration objects used throughout the API, including language definitions, operation states, and input/output configurations.

class SupportedLanguages: ...
class DetectedLanguage: ...
class Translation: ...
class Glossary: ...
class AdaptiveMtDataset: ...
class Dataset: ...
class Model: ...
class OperationState: ...

Data Structures and Enums