An open API service indexing awesome lists of open source software.

https://github.com/minhazulmin/laravel-multi-language

For Sponsor WhatsApp me +8801751337061. Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application.
https://github.com/minhazulmin/laravel-multi-language

language-switching-in-laravel laravel laravel-multi-language localization minhazulmin multi-language multi-languages

Last synced: about 1 month ago
JSON representation

For Sponsor WhatsApp me +8801751337061. Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application.

Awesome Lists containing this project

README

          

# Laravel-Multi-Language
Laravel's localization features provide a convenient way to retrieve strings in various languages, allowing you to easily support multiple languages within your application.

![Sponsor](https://i.postimg.cc/QdPWVf9Y/Screenshot-1.png)
**For Sponsor WhatsApp me +8801751337061**
Watch video on YouTube: https://www.youtube.com/minit61
Watch video on Facebook: https://www.facebook.com/minit61

## Output
![App Screenshot](https://i.postimg.cc/pX9Zkc1X/Screenshot-1.png)

## Installation

**[Step - 1]** **Create new Project:**

(Open PowerShell In Your Local Machine and put this command)
```bash
Laravel new laravel-multi-languages
```
**[Step - 2]** **Remove unnecessary code from welcome.blade.php, After that copy and past code into this file:**
```bash


Laravel






Login
Sign-up




get('locale') == 'en' ? 'selected' : '' }}> {{ __('home.English') }}

get('locale') == 'bn' ? 'selected' : '' }}> {{ __('home.Bangla') }}








{{ __('home.title') }}




var url = "{{ route('change_lang') }}";
document.querySelectorAll(".changeLang").forEach(function(element) {
element.addEventListener('change', function() {
window.location.href = url + "?lang=" + this.value;
});
});

```

**[Step - 3]** **create a folder on root directory (lang):** Then Create two folder **en** and **bn** After that make a file **home.php** ( See the folder structure in below )
```bash
lang/en/home.php
lang/bn/home.php
```
**[Step - 4]** **Copy and past into file**

**lang/en/home.php**
```bash
'I love coding',
'English' => 'English',
'Bangla' => 'Bangla',
];
?>
```

**lang/bn/home.php**
```bash
'আমি কোডিং ভালোবাসি',
'English' => 'ইংরেজি',
'Bangla' => 'বাংলা',
];
?>
```
**[Step - 5]** **Make a Route on the web.php:**
```bash
use App\Http\Controllers\LangController;

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

```
**[Step - 6]** **Make a controller:**
```bash
php artisan make:controller LangController
```

**Copy and post on the controller**
```bash
lang );
session()->put( 'locale', $request->lang );

return redirect()->back();
}
}
```
**[Step - 7]** **Make a Middleware:**
```bash

php artisan make:middleware LanguageManager

```
**[Step - 8]** **Copy and past on the middleware**
```bash
has( 'locale' ) ) {
App::setLocale( session()->get( 'locale' ) );
}

return $next( $request );
}
}

```
**[Step - 9]** **Then register middleware on the bootstrap/app.php, Inside the withMiddleware; Look like this**
```bash
->withMiddleware( function ( Middleware $middleware ) {
$middleware->web( append: [
\App\Http\Middleware\LanguageManager::class,
] );
} )
```
**[Step - 10]** **run the command on the project terminal**
```bash
php artisan serve
```
Hit the url
```bash
http://127.0.0.1:8000/
```
## Authors

- [@minhazulmin](https://www.github.com/minhazulmin)