Skip to content

Latest commit

 

History

History

translate

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Google Cloud Translate API Samples

Open in Cloud Shell

Description

These samples show how to use the Google Cloud Translate API from PHP.

Build and Run

  1. Enable APIs - Enable the Translate API and create a new project or select an existing project.
  2. Download The Credentials - Configure your project using Application Default Credentials. Click "Go to credentials" after enabling the APIs. Click "Create Credentials" and select "Service Account Credentials" and download the credentials file. Then set the path to this file to the environment variable GOOGLE_APPLICATION_CREDENTIALS:
    $ export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
  1. Clone the repo and cd into this directory
    $ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
    $ cd php-docs-samples/translate
  1. Install dependencies via Composer. Run php composer.phar install (if composer is installed locally) or composer install (if composer is installed globally).
  2. Run with the command php src/SNIPPET_NAME.php. For example:
    $ php src/list_languages.php
    af: Afrikaans
    sq: Albanian
    am: Amharic
    ...
    
    $ php src/translate.php "This is my text to translate" fr
    Source language: en
    Translation: Ceci est mon texte à traduire

Contributing changes

Licensing