Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

298
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda