PHP code example of webklex / translator
1. Go to this page and download the library: Download webklex/translator 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/ */
webklex / translator example snippets php
'providers' => [
Webklex\Translator\Providers\TranslatorServiceProvider::class,
Webklex\Translator\Providers\TranslatorBladeServiceProvider::class,
];
php
protected $routeMiddleware = [
'translator' => Webklex\Translator\Middleware\TranslatorMiddleware::class,
];
php
/**
* Change the current language
*
* @param string $locale
* @return \Illuminate\Http\RedirectResponse
*/
public function changeLanguage($locale){
if(in_array($locale, config('translator.available'))){
Session::put('locale', $locale);
Session::save();
app()->setLocale($locale);
}
return redirect()->back();
}
php
Route::get('/language/{locale}', 'YourControllerName@changeLanguage');
php
php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider"
php
php artisan vendor:publish --provider="Webklex\Translator\Providers\TranslatorServiceProvider" --tag="config"
php
'aliases' => [
'Lang' => Webklex\Translator\Facades\TranslatorFacade::class
];
php
if (!function_exists('_t')) {
/**
* Shorthand translation
* @param string $string
* @param string $locale
*
* @return string
*/
function _t($string, $locale = null)
{
return Webklex\Translator\Facades\TranslatorFacade::get($string, $locale);
}
}