PHP code example of akibtanjim / google-translate

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

    

akibtanjim / google-translate example snippets

config/app.php
Functions.php



  function sessionFlush(){
    Session::forget('source');
    Session::forget('target');
  }

  function setTarget($target){
    Session::put('target',$target);
  }

  function setSource($source){
    Session::put('source',$source);
  }

  function translateText($text){
    $src = Session::get('source');
    $target = Session::get('target');
    if($target == '' || $target == null) return $text;
    if($src == '' || $src == null) 
    {
      $src= env('BaseLanguage');
      Session::put('source',env('BaseLanguage'));
    }
    if($src == $target) return $text;
    else{
      $translation=TranslateText::translate($src,$target,$text);
      return $translation;
    }
  }


  composer dump-autoload



  php artisan make:controller ExampleController



  

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Session;

    class ExampleController extends Controller
    {
        public function index(){
          return view('test');
        }

        public function setTarget(Request $request){
          Session::put('target',$request->target);
          return 1;
        }
    }
  
resources/views/test.blade.php
web.php

  php artisan serve