How to create multi language website by  laravel 9 | WebJourney

How to create multi language website by laravel 9 | WebJourney

Welcome to everyone in a new lesson. Today we will learn how to create a multi language website using latest version of laravel 9. Also we will see how to change language and entire website contents of that language. we have the following steps to do this.



1. Download freash laravel project
2. Create folders and files inside resources folder
3. Create routes in web.php
4. Create controller
5. Create view file inside views folder
6. Create middleware




Step-1: Download freash laravel project


At the first setp we need to create a fresh laravel project using composer. You may also install by laravel installer. Let's build an app multi-lang

//BY laravel installer 
laravel new multi-lang

//By composer
composer create-project laravel/laravel multi-lang




Step-2: Create folders and files inside resources folder 


Now we create a folder lang inside resources and inside lang we again create three folders named en for English, sp for Spanish and bn for Bengali. After create folders successfully we create a .php file name text.php inside those three folder show in bellow image.


Open text.php file from each directory and paste bellow code.



return [
  'content'=>'Hello Devs, Welcome To WebJourny',




return [
  'content'=>'Hola desarrolladores, bienvenidos a WebJourny',




return [
  'content'=>'হ্যালো দেবগণ, ওয়েবজার্নিতে স্বাগতম',




Step-3: Create routes in web.php




use Illuminate\Support\Facades\Route;
use App\Http\Controllers\LangController;

Route::get('/', function () {
    return view('welcome');

Route::get('lang', [LangController::class, 'lang']);
Route::get('lang/change', [LangController::class, 'lang_change'])->name('lang.change');




Step-4: Create controller


Now we will create controller and implements logics in controller

php artisan make:controller LangController




namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App;

class LangController extends Controller
    public function lang()
        return view('lang');

    public function lang_change(Request $request)
        return redirect()->back();




Step-5: Create view file inside views folder



<!DOCTYPE html>
    <title>Multi Language Website with Laravel 9</title>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="" rel="stylesheet">
    <div class="container text-center">
        <h2>Multi Language Website with Laravel 9</h2>
        <div class="row">
         <div class="col-md-3"></div>
            <div class="col-md-6">
                <strong>Select Language: </strong>
                <select class="form-control lang-change">
                    <option value="en" {{ session()->get('lang_code')=='en' ? 'selected' : ''}}>English</option>
                    <option value="sp" {{ session()->get('lang_code')=='sp' ? 'selected' : ''}}>Spanish</option>
                    <option value="bn" {{ session()->get('lang_code')=='bn' ? 'selected' : ''}}>Bengali</option>
        <h4 class="mt-5">{{ __('text.content') }}</h4>
<script src=""></script>
<script type="text/javascript">
  var url = "{{ route('lang.change') }}";

     let lang_code = $(this).val();
      window.location.href = url + "?lang="+ lang_code;





Step-6. Create middleware


Finally create a middleware name LangManage and write some logics also we have to register this middleware in App\Http\Kernel.php

php artisan make:middleware LangManage


App\Http\Middleware\ LangManage.php


namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use App;

class LangManage
     * Handle an incoming request.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
    public function handle(Request $request, Closure $next)
        return $next($request);




    protected $middlewareGroups = [
        'web' => [

        'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,


Ok Now run artisan server using the bellow command and test your app.

php artisan serve


Paste this url in browser



Hope this will help you. Thanks




If you like what you are reading, please think about buying us a coffee as a token of appreciation.

Buy Me A Coffee

We appreciate your support and are committed to providing you useful and informative content.

We are thankful for your ongoing support 


  • Share This: