How to change message languages dynamically in Laravel | Change localisation in Laravel

Create folders inside resources/lang for different different languages and write message files with same name and also write same key among all the message files.

like I have 2 languages EN and ES.. then I created 2 folders, one is en and second is es.

Inside both folders I created password files. like:

en/passwords.php

es/passwords.php

Now I can call any of these 2 language messages by their file and key name like:

here I can pass the language code dynamically in the constructor and message of that language will be called.

welcome.blade.php

For changing message language all over the project, We can use session an can set the language or we also can create a middleware for this.

We also can get the current language of the project messages like:

We also can perform some operations conditionally like:

 

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *