hoyvoy / laravel-subdomain-localization

Easy subdomain localization for Laravel - Language detection based on subdomain, browser settings and cookies.
MIT License
8 stars 3 forks source link

Route translation string and route name must match #5

Open gonssal opened 6 years ago

gonssal commented 6 years ago

Hi.

I think you should document in the README that, when using named routes and route translation together, if you want Router::getCurrentVersions() to work properly, you must give each route exactly the same name that you are using in Router::resolve().

For example, if you have:

Route::get(Router::resolve('routes.blog'), 'BlogController@index');

you have to name it routes.blog:

Route::get(Router::resolve('routes.blog'), 'BlogController@index')->name('routes.blog');

or getCurrentVersions() won't return the translated routes.

Likewise, in the README's example to get the localized version of a route, if you wanted to name it, you should explain that it needs to be named exactly the same as the translation key. In the example:

<a href="{{ Router::url('user_profile', [ 'username' => 'JohnDoe' ], 'fr') }}">See JohnDoe's profile</a>

if you define the route as follows:

Route::get(Router::resolve('routes.user_profile'), 'UsersController@profile')->name('user_profile');

it won't work, it will return the current url.

This is due to how findRoutePathByName() is written.

maguilar92 commented 6 years ago

@gonssal You are free to submit a pull request to patch this issue.

If it is not possible, I will review it as soon as possible.

Thank you very much!