PHP code example of darvis / laravel-google-translate

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

    

darvis / laravel-google-translate example snippets


use Darvis\LaravelGoogleTranslate\GoogleTranslateService;

$translator = app(GoogleTranslateService::class);

$translator->translate('Hallo wereld', 'en');            // for example "Hello world"
$translator->translateHtml('<p>Hallo</p>', 'en');        // for example "<p>Hello</p>"
$translator->translateBatch(['Hallo', 'Wereld'], 'en');  // for example ["Hello", "World"]

use Darvis\LaravelGoogleTranslate\Traits\HasGoogleTranslate;
use Illuminate\Database\Eloquent\Model;

class Page extends Model
{
    use HasGoogleTranslate;

    protected $fillable = ['pid', 'locale', 'title', 'content', 'slug'];

    protected $translatableFields = ['title', 'content'];

    protected $htmlFields = ['content'];
}

$english = $page->createTranslation('en', ['slug' => 'about-us']);   // a new row, or null