PHP code example of datlechin / laravel-google-translate

1. Go to this page and download the library: Download datlechin/laravel-google-translate 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/ */

    

datlechin / laravel-google-translate example snippets


use Datlechin\GoogleTranslate\Facades\GoogleTranslate;

// Using facade
$result = GoogleTranslate::source('en')
    ->target('vi')
    ->translate('Hello world!');

$result->translatedText(); // Chào thế giới!

$result->getAlternativeTranslations();
//[
//    [
//        0 => 'Chào thế giới!',
//        1 => 'Xin chào thế giới!',
//        2 => 'Chào cả thế giới!',
//    ],
//]

$result->getSourceText(); // Hello world!
$result->getSourceLanguage(); // en