Open Legoraccio opened 1 year ago
I solve setting the 'cookie_localization' => false
in config.
It stills a bug?
Stills, but you can workaround this issue creating a middleware and moving "tongue()->detect()" inside.
is there any solution for this problem?
solved :
1. Create the Listener Class:
// app/Listeners/DetectLanguageListener.php
namespace App\Listeners;
use Laravel\Octane\Events\RequestReceived;
use Illuminate\Http\Request;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class DetectLanguageListener
{
/**
* Handle the event.
*
* @param RequestReceived $event
* @return void
*/
public function handle(RequestReceived $event)
{
// Extract the request object from the event
$request = $event->request;
// Detect the user's locale and set it
tongue()->detect();
// Set the locale for Carbon dates
Carbon::setLocale(tongue()->current());
// Log the current locale for debugging purposes
Log::debug("Localize: " . tongue()->current());
}
}
2. Updated octane.php:
// config/octane.php
use Laravel\Octane\Events\RequestReceived;
use App\Listeners\DetectLanguageListener;
return [
/*
|--------------------------------------------------------------------------
| Octane Listeners
|--------------------------------------------------------------------------
|
| All of the event listeners for Octane's events are defined below. These
| listeners are responsible for resetting your application's state for
| the next request. You may even add your own listeners to the list.
|
*/
'listeners' => [
WorkerStarting::class => [
EnsureUploadedFilesAreValid::class,
EnsureUploadedFilesCanBeMoved::class,
],
RequestReceived::class => [
...Octane::prepareApplicationForNextOperation(),
...Octane::prepareApplicationForNextRequest(),
DetectLanguageListener::class, // Add this line
],
Hi, I'm trying to use Laravel-Tongue with Laravel Octane. All works as expected, except for the automatic language detection by client settings.
So, if I access the application with a language (IT in my case) that is different from the default (EN), the
tongue()->detect();
do not detect the correct language.I run the
tongue()->detect()
fun from a custom middleware, because theboot()
function in Octane run only at server startup.Laravel version: 10.15.0 Tongue version: 5.0.0
This is the middleware:
And my localization.php
If I change manually the language with
https://it.foo.bar
, all works.Any idea? Thanks!