1. Go to this page and download the library: Download samsonphp/google_translate 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/ */
samsonphp / google_translate example snippets
class Google_TranslateConfig extends \samson\core\Config
{
public $apiKey = 'Your_Google_API_Key';
}
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');
// Source text
$helloWorld = 'Hello World';
// Translated text
$bonjourLeMonde = $trans->source('en')->target('fr')->trans($helloWorld);
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');
// Source text
$helloWorld = 'Hello World';
// Translated text
$bonjourLeMonde = $trans->source('gb')->target('fr')->trans($helloWorld);
echo 'Translated string - "'.$bonjourLeMonde.'"; <br>';
// Is false, because gb locale is not found in Google language codes.
echo 'Request status is '.$trans->lastRequestStatus();
/** @var \samson\google\Translate $trans Get SamsonPHP GoogleTranslate module */
$trans = & m('google_translate');
// Source strings
$myStrings = array('white dog', 'cat', 'rabbit', 'squirrel');
// Translate it
$myTranslatedStrings = $trans->source('en')->target('fr')->trans($myStrings);
// Look at the response
print_r($myTranslatedStrings);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.