PHP code example of dejurin / php-google-translate-for-free

1. Go to this page and download the library: Download dejurin/php-google-translate-for-free 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/ */

    

dejurin / php-google-translate-for-free example snippets



use \Dejurin\GoogleTranslateForFree;

$source = 'en';
$target = 'ru';
$attempts = 5;
$text = 'Hello';

$tr = new GoogleTranslateForFree();
$result = $tr->translate($source, $target, $text, $attempts);

var_dump($result); 

/* 
	string(24) "Здравствуйте" 
*/

$source = 'en';
$target = 'ru';
$attempts = 5;
$arr = ['hello','world'];

$tr = new GoogleTranslateForFree();
$result = $tr->translate($source, $target, $arr, $attempts);

var_dump($result); 

/*
	array(2) {
	  [0]=>
	  string(24) "Здравствуйте"
	  [1]=>
	  string(6) "Мир"
	}

*/

composer