PHP code example of enupal / yandex-translate
1. Go to this page and download the library: Download enupal/yandex-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/ */
enupal / yandex-translate example snippets
php
use Enupal\YaTranslate\Translate;
try {
$tr = new Translate('yourApiKey');
$result = $tr->translate("Hey baby, what are you doing tonight?", 'fr');
echo $result; // Hey bébé, tu fais quoi ce soir?
echo $result->sourceText(); // Hey baby, what are you doing tonight?
echo $result->translationDirection(); // en-fr
var_dump($result->translation()); // array (size=1)
// 0 => string 'Hey bébé, tu fais quoi ce soir?'
} catch (\Enupal\YaTranslate\TranslateException $e) {
//Handle exception
}