PHP code example of mgcodeur / super-translator

1. Go to this page and download the library: Download mgcodeur/super-translator 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/ */

    

mgcodeur / super-translator example snippets

 php
 Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'en';
$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);
echo $translatedText;
// Output: Bonjour le monde!
 php
 Mgcodeur\SuperTranslator\GoogleTranslate;

$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translateAuto($to, $text);
echo $translatedText;
// Output: Bonjour le monde!
 php
 Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'auto';
$to = 'fr';
$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);
echo $translatedText;
// Output: Bonjour le monde!
 php
 Mgcodeur\SuperTranslator\GoogleTranslate;

$from = 'en';
$to = ['fr', 'es', 'de'];

$text = 'Hello World!';

$translatedText = GoogleTranslate::translate($from, $to, $text);

//Nb: the $translatedText variable is an array

# Output: [
#    'fr' => 'Bonjour le monde!',
#    'es' => '¡Hola Mundo!',
#    'de' => 'Hallo Welt!'
# ]