PHP code example of gino-pane / phpolyglot

1. Go to this page and download the library: Download gino-pane/phpolyglot 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/ */

    

gino-pane / phpolyglot example snippets


$phpolyglot = new PHPolyglot($config, $env);

function translate(string $text, string $languageTo, string $languageFrom = ''): TranslateResponse

function translateBulk(array $text, string $languageTo, string $languageFrom = ''): TranslateResponse

$response = (new PHPolyglot())->translate('Hello world', 'it')->getTranslations(); // [ 0 => Ciao mondo ]

function lookup(string $text, string $languageFrom): DictionaryResponse

function lookup(string $text, string $languageFrom, string $languageTo): DictionaryResponse

$response = (new PHPolyglot)->lookup('Hello', 'en)->getEntries();

$synonyms = implode(", ", $response[0]->getSynonyms());

$output = <<<TEXT
Initial word: {$response[0]->getTextFrom()}

Part of speech: {$response[0]->getPosFrom()}
Transcription: {$response[0]->getTranscription()}

Main alternative: {$response[0]->getTextTo()}
Synonyms: {$synonyms}
TEXT

echo $output

/**
Initial word: hello
  
Part of speech: noun
Transcription: ˈheˈləʊ

Main alternative: hi
Synonyms: hallo, salut
*/

function spellCheck(string $text, string $languageFrom = ''): SpellCheckResponse

function spellCheckBulk(array $texts, string $languageFrom = ''): SpellCheckResponse

$corrections = $phpolyglot->spellCheckText('Helo werld', $languageFrom)->getCorrections();

/**
array(1) {
  [0] =>
  array(2) {
    'Helo' =>
    array(1) {
      [0] =>
      string(5) "Hello"
    }
    'werld' =>
    array(1) {
      [0] =>
      string(5) "world"
    }
  }
}
*/


public function speak(
    string $text,
    string $languageFrom,
    string $audioFormat = TtsAudioFormat::AUDIO_MP3,
    array $additionalData = []
): TtsResponse

function storeFile(string $fileName = '', string $extension = '', string $directory = ''): string

(new PHPolyglot())->speak('Hello world', 'en')->storeFile(); // stores 3e25960a79dbc69b674cd4ec67a72c62.mp3