/** * @param $language * @param $expectedLanguage * * @dataProvider dataSetGetLanguage */ public function testSetGetTranslateTo($language, $expectedLanguage) { $dictionaryClient = new DictionaryClient(''); $dictionaryClient->setTranslateTo($language); $this->assertEquals($expectedLanguage, $dictionaryClient->getTranslateTo()); }
/** * checkOptions * * @throws Exception\InvalidSettingsException * @return void * @static */ public static function checkSettings() { //Method inherited from \Yandex\Common\AbstractPackage \Yandex\Dictionary\DictionaryClient::checkSettings(); }
<?php $settings = (require_once '../settings.php'); use Yandex\Dictionary\DictionaryClient; use Yandex\Common\Exception\ForbiddenException; use Yandex\Dictionary\Exception\DictionaryException; $errorMessage = false; // Is auth if (isset($_COOKIE['yaAccessToken']) && isset($_COOKIE['yaClientId'])) { if (!isset($settings["dictionary"]["key"]) || !$settings["dictionary"]["key"]) { throw new DictionaryException('Empty dictionary key. Get key from https://tech.yandex.ru/keys/get/?service=dict'); } $dictionaryClient = new DictionaryClient($settings["dictionary"]["key"]); if (isset($_POST['word']) && $_POST['word'] && isset($_POST['language']) && $_POST['language']) { $translation = explode('-', $_POST['language']); if (count($translation) === 2) { $from = $translation[0]; $to = $translation[1]; $dictionaryClient->setTranslateFrom($from)->setTranslateTo($to); $result = $dictionaryClient->lookup($_POST['word']); if ($result) { /** @var \Yandex\Dictionary\DictionaryDefinition $dictionaryDefinition */ $dictionaryDefinition = $result[0]; $dictionaryTranslation = $dictionaryDefinition->getTranslations(); /** @var \Yandex\Dictionary\DictionaryTranslation $dictionaryTranslation */ $dictionaryTranslation = $dictionaryDefinition->getTranslations()[0]; $word = $dictionaryTranslation->getText(); } } } try {