PHP code example of canadadry / google-translate-php
1. Go to this page and download the library: Download canadadry/google-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/ */
canadadry / google-translate-php example snippets
use Stichoza\GoogleTranslate\GoogleTranslate;
$tr = new GoogleTranslate('en'); // Translates into English
$tr = new GoogleTranslate(); // Translates to 'en' from auto-detected language by default
$tr->setSource('en'); // Translate from English
$tr->setSource(); // Detect language automatically
$tr->setTarget('ka'); // Translate to Georgian
// Set proxy to tcp://localhost:8090
$tr->setOptions(['proxy' => 'tcp://localhost:8090'])->translate('Hello');
// Set proxy to socks5://localhost:1080
$tr->setOptions(['proxy' => 'socks5://localhost:1080'])->translate('World');
use Stichoza\GoogleTranslate\Tokens\TokenProviderInterface;
class MyTokenGenerator implements TokenProviderInterface
{
public function generateToken(string $source, string $target, string $text) : string
{
// Your code here
}
}
$tr->setTokenProvider(new MyTokenGenerator);
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.