Home Laravel Laravel 8 Localization Multi Language Working Functionality

Laravel 8 Localization Multi Language Working Functionality

by therichpost
0 comments
Laravel 8 Localization Multi Language Working Functionality

Hello guy’s, welcome back to my blog. Today in this blog post, I am going to show you, Laravel 8 Localization Multi Language Working Functionality.

Working Video

Guys if you are new in Laravel 8 the please check below link:

Laravel 8 Tutorials

Here is the working images for both the languages English and Spanish:

english_language
spanish_language

Now here I am sharing the working and easy steps:

1. Guy’s very first I created two folders(en, es) inside resources\lang folder:

Here you can see clearly:

language_folders

2. After that, I created files messages.php inside both resources/lang/en and resources/lang/es folders:

mesage_file_en
mesage_file_es

Guy’s here is the working code snippet for Laravel 8 Localization Multi Language Working Functionality and please use carefully:

3. Now guy’s I added below code inside messages.php in resources/lang/es folder:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Pagination Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines are used by the paginator library to build
    | the simple pagination links. You are free to change them to anything
    | you want to customize your views to better match your application.
    |
    */

    "I love programming." => "Me encanta programar."

];
?>

4. Now guy’s I added below code inside messages.php in resources/lang/en folder:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | Pagination Language Lines
    |--------------------------------------------------------------------------
    |
    | The following language lines are used by the paginator library to build
    | the simple pagination links. You are free to change them to anything
    | you want to customize your views to better match your application.
    |
    */

    "I love programming." => "I love programming."

];
?>

5. To call messages.php text, I added below code inside resources/views/welcome.blade.php file:

<center><h1>{{ __('messages.I love programming.') }}<h1></center>

6.  Guy’s finally, I added the below code inside routes/web.php file:

Route::get('/{locale}', function ($locale) {
    App::setLocale($locale);

    return view('welcome');
});

7. In the end I ran below commands inside my project terminal:

php artisan serve

execute urls:

http://127.0.0.1:8000/es // for spanish

http://127.0.0.1:8000/en // for english

Guy’s if you have any kind of query or suggestion or any requirement then feel free to comment below.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.

Jassa

Thanks

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.