PHP code example of szy4211 / translate

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

    

szy4211 / translate example snippets


use Szy4211\Translate\Translate;

$config = [
    'default' => 'baidu', // 默认网关配置
    // 网关列表
    'gateways' => [
        'baidu' => [
            'app_id' => '',
            'app_secret' => '',
            'http_timeout' => 5.0, // 超时时间
            'http_options' => [],
        ],
        // ...
    ],
];

$translate = new Translate($config);
$transResult = $translate->translate('Hello');
echo $translate->getDstMessage(); // 你好



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Szy4211\Translate\Translate;

class TranslateController extends Controller
{
    public function show(Request $request, Translate $translate, $query)
    {
        return $translate->translate($query);
    }
}
shell script
php artisan vendor:publish --provider="Szy4211\Translate\TranslateServiceProvider"
ini
TRANS_BAIDU_APP_ID='xxx'
TRANS_BAIDU_APP_SECRET='xxx'