Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Alvaro_SE's avatar

Routes laravel translation

After much testing and searching, I can not find the solution.

My problem is that I have, for example the route '/services', '/servicios' in spanish.

If my website is in english, all texts are correctly shown in english, same in spanish. But the problem is with the text links, only appear in default locale.

In routes/web.php:

Route::get(trans('rutas.servicios'), 'ServiceController@index')->name('servicios')

File lang/es/rutas.php:

return [
   'servicios' => '/servicios',
];

File lang/en/rutas.php:

return [
   'servicios' => '/services',
];

and link html:

<a href="{‌{ route('servicios') }}">@lang('menus.servicios')</a> 

My goal is to use translated urls without using laravel prefix. That is to say:

https://www.myweb.com/services  ~ english
https://www.myweb.com/servicios ~ spanish

share the same Route controller.

Any help? Lot of thanks for your time!

0 likes
2 replies
Alvaro_SE's avatar
Alvaro_SE
OP
Best Answer
Level 1

I was already reading that post. But my idea was to do it without using prefixes. And finally I found the solution. I discovered that laravel performs route mapping before selecting the language. So what I did was to set the language before this, but the session variables and cookies load after this. But I finally discovered that the cached variables satisfied my needs.

Please or to participate in this conversation.