1. Go to this page and download the library: Download impronta48/ibmwatson 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/ */
impronta48 / ibmwatson example snippets
declare(strict_types=1);
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use impronta48\IBMWatson;
$w = new IBMWatson($this->apikey, $this->url);
$resJson = $w->translateSentence('hello', 'en', 'it');
$resJson = $w->translateSentence(['hello','goodbye'], 'en', 'it');
//Convert the Json String in a Object
$res = json_decode($resJson);
echo $res->translations[0]->translation;
// returns ciao
echo $res->word_count;
// returns 1
echo $res->character_count;
// returns 5
$w = new IBMWatson($this->apikey, $this->url);
$lang = $w->identifyLanguage('Mi chiamo Massimo e scrivo molto bene in italiano');
echo $lang;
// returns 'it'