I have upgraded my Laravel 8 application to version 9, and according to the docs: upgrade guide, the resources/lang directory is now located in the root project directory (lang).
I've moved the lang directory to the root directory of my project, but it does not seem to work.
// config/app.php
'locale' => 'pt-BR',
and
// lang/pt-BR/messages.php
return [
'welcome' => 'Welcome to the app!',
];
Controller
return response()->json([
'message' => Lang::get('messages.welcome') // it returns "messages.welcome"
]);
But when I change the lang directory back to /resources/lang, it works fine like in previous laravel versions. So I created a new fresh project of Laravel 9, and it worked, which leads me to think that some additional configuration is needed, but it's not documented in the upgrade guide. My composer.json dependencies are precisely the same as the new laravel project. Is there any additional configuration that needs to be done for Laravel to recognize the directory?
So I found the solution, the "problem" was that I didn't removed the resources/lang directory so Laravel was using that directory instead of the lang directory in the base path of the application.
After removing the resources/lang directory it worked as expected. Thanks to @lagbox comment.
@IGP answer also worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With