PHP code example of kinghang / laravel-translate
1. Go to this page and download the library: Download kinghang/laravel-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/ */
kinghang / laravel-translate example snippets
namespace App\Http\Controllers;
use KingHang\LaravelTranslate\Translate;
class IndexController
{
/**
* 根据配置文件翻译
* @param string $content
* @return string
**/
public function translateDefault($content)
{
return Translate::translate($content);
}
/**
* 自定翻译目标语言
* @param string $content
* @return string
**/
public function translateToJp($content)
{
return Translate::to('jp')->translate($content);
}
/**
* 自定源及目标语言
* @param string $content
* @return string
**/
public function translateFromEnToJp($content)
{
return Translate::from('en')->to('jp')->translate($content);
}
}
shell script
php artisan vendor:publish --provider="KingHang\LaravelTranslate\ServiceProvider::class"