PHP code example of darrynten / google-cloud-translate-php

1. Go to this page and download the library: Download darrynten/google-cloud-translate-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

darrynten / google-cloud-translate-php example snippets


use DarrynTen\GoogleCloudTranslatePhp\GoogleCloudTranslate;

// Config options
$config = [
  'projectId' => 'my-awesome-project'  // At the very least
];

// Make a translator
$translate = new GoogleCloudTranslate($config);

// Get information
$translate->languages();
$translate->localizedLanguages();

// Detect languages
$translate->detectLanguage($string);
$translate->detectLanguageBatch([$strings]);

// Translate
$translate->translate($string);
$translate->translateBatch([$strings]);

// Set optional things
$language->setType('html');
$language->setModel('base');
$language->setTargetLanguage('en');
$language->setSourceLanguage('es');

// Extra features
$language->setCaching(false);
$language->setCheapskate(false);
$language->setCheapskateCount(50);

// Full config options
$config = [
  'projectId' => 'my-awesome-project',     // che
  'cheapskate' => $boolean,                // cheaper detection calls
  'cheapskateCount' => 100,                // how cheap?
];

// authCache, authCacheOptions, authHttpHandler and httpHandler are not
// currently implemented.