PHP code example of yandex / translate-api
1. Go to this page and download the library: Download yandex/translate-api 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/ */
yandex / translate-api example snippets
use Yandex\Translate\Translator;
use Yandex\Translate\Exception;
try {
$translator = new Translator($key);
$translation = $translator->translate('Hello world', 'en-ru');
echo $translation; // Привет мир
echo $translation->getSource(); // Hello world;
echo $translation->getSourceLanguage(); // en
echo $translation->getResultLanguage(); // ru
} catch (Exception $e) {
// handle exception
}