Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

296
Vistas
Laravel get route by locale

Currently, I've got the following route in my web app.

Route::get(__('routes.account.dogs'), 
    [DogController::class, 'index'])->name('dog.index')->middleware('auth');

I specify the URL translation for the route in two different language files.

return [
    //Account
    'account' => [
        'dogs' => 'honden',
    ]
];

When I send a queued email with this link, I want to translate the link on the user's locale (saved in the database). So I want to get this route based on the user's locale, but app()->setLocale($user->locale); cannot be used because it's a queued job. How can I fix this?

In a perfect world it would be something like:

route('dog.index', [], $user->locale);
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

laravel __() helper function also accepts the optional 3rd argument $locale for setting the locale to translate.

So you could use the $user->locale in the helper as follows.

url(__('account.dogs', [], $user->locale));
over 4 years ago · Santiago Trujillo Denunciar

0

As @Vincent Decaux suggested, you need a library to make your life easier. You could use the one they use or the one I use arcanedev/localization.

Once you set a middleware, everything will be taken care of. But I am concerned regarding your comment:

Yes indeed! but then I still need to do something with the domain. For example .de or .com

Why not use the current domain (.com?) and simply add a directory /en or whatever locale you need instead? It seems inconvenient to me to change the entire domain.

over 4 years ago · Santiago Trujillo Denunciar

0

When you use Mail::to(), you can use locale() to choose the translation

Mail::to($user->email)
    ->locale($user->locale)
    ->queue(new YourEmail());

https://laravel.com/docs/9.x/mail#localizing-mailables

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda