1. Go to this page and download the library: Download tooinfinity/lingua 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/ */
Route::middleware(['web', 'lingua:common,validation'])->get('/dashboard', function () {
// ...
});
use TooInfinity\Lingua\Facades\Lingua;
Lingua::getLocale(); // Get current locale
Lingua::setLocale('fr'); // Set locale (optionally persists cookie)
Lingua::supportedLocales(); // Get supported locales
Lingua::translations(); // Get all translations (missing keys fall back to default locale)
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Validation\Rule;
use TooInfinity\Lingua\Lingua;
class LocaleController
{
public function __invoke(Request $request, Lingua $lingua)
{
$validated = $request->validate([
'locale' => ['