a way to change Localization in Laravel 9 without session()->put('locale', $locale); ?
Greetings everyone,
I wonder if there is a way in Laravel 9 to figure out how change localization without implementing it in a session ? session()->put('locale', $locale);
thank you for your time and reply. Good question ? SO the localisation by default must use sessions right ? There is no way to implement it without ?
I was thinking there is a way to implment the localisation change globally without using sessions
@mir86 Usually we would put it into the Session so it follows the User during their visit. Why don't you want to use the Session?
Otherwise, you could set the locale for the current request using a URL segment (/en/products/1) if you prefer; but you need somewhere to store this so you can build the correct URLs for internal links (so every link on your site has the locale included) specific to the current User. You could put to a temporary cache (array driver) to persist the value for the duration of the current request; then repeat for each subsequent Request.
You can add a route middleware to grab the locale from the URL; and therefore set the locale for the Request
By default, you always have a Session started when you visit a Laravel application; but this does not mean you have authenticated users (Session !== Authentication)
hello
First make your locale folder inside \resources\lang\YOUR_LOCALE_NAME .
Then add file messages. php or as per your need. ...
Then go to \config\app. php and set the locale as your LOCALE_FOLDER_NAME .
Remember to set fallback_locale in app. php which will be used in case YOUR_LOCALE_NAME is not found.
I do not know it will helpful or not just trying to help you so please let us know . https://www.benefitscal.biz/
@melissa354 thank you for your time and reply. "Set the locale as your LOCALE_FOLDER_NAME " didn t get it. I have this at config/app.php
...
'locale' => 'en','fr','esp',
...
'fallback_locale' => 'en',