Пример #1
0
 public function translate($text, $sourceLanguage, $targetLanguage)
 {
     if ($this->_api !== null) {
         $postData = ['text' => $text, 'source' => $sourceLanguage, 'target' => $targetLanguage, 'projectId' => $this->_projectId];
         $body = \Requests::post($this->_api, [], $postData)->body;
         $result = json_decode($body);
         $result = idp($result, 'result', null);
         if ($result === null) {
             return $text;
         }
         return idp($result, "text", $text);
     } else {
         throw new \Exception("No Translate Endpoint specified in config file", 400);
     }
 }
Пример #2
0
 public function testIdp()
 {
     $object = new stdClass();
     $object->name = "apple";
     $this->assertEquals("apple", idp($object, "name", "pear"));
     $this->assertEquals("orange", idp($object, "noprop", "orange"));
 }