These samples show how to use the Google Cloud Translate API from PHP.
- Enable APIs - Enable the Translate API and create a new project or select an existing project.
- 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
- Clone the repo and cd into this directory
$ git clone https://github.com/GoogleCloudPlatform/php-docs-samples
$ cd php-docs-samples/translate
- Install dependencies via Composer.
Run
php composer.phar install
(if composer is installed locally) orcomposer install
(if composer is installed globally). - 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
- See CONTRIBUTING.md
- See LICENSE