0
votes

Using Laravel 5.2.41

Using following translation package: mcamara/laravel-localization

Link inside my view :

<a href="{{ LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ["id" => Auth::user()->id]) }}"> Edit Link</a>

routes.php files inside Lang/fr & Lang/nl

<?php
return [
    'account-edit'      => "account/wijzig-gegevens/{id}", 
];

<?php
return [
    'account-edit'      => "donnees/modifier-donnees/{id}", 
];

Laravel routes file:

 Route::group([

    'prefix' => LaravelLocalization::setLocale(),
    'middleware' => ['localize','localeSessionRedirect', 'localizationRedirect' ]

    ], function()
    {

Route::get(LaravelLocalization::transRoute('routes.account-edit'),'AccountController@edit');

});

When i look at the link in my default language (nl) i get the correct link like so:

<a href="http://blabla.dev/nl/account/wijzig-gegevens/1">Edit Link</a>

But when i change my language to french i get following link:

<a href="http://blabla.dev/fr/donnees/modifier-donnees/{id}">Edit Link</a>

Can't figure out why this is happening

1
I really do not have any experience with this translation package. However I see you are translating, trans('routes.account-edit'), in your ...::getLocalizeURL(.... Try to remove it. - Thomas Van der Veen
@ThomasVanderVeen thanks for your response, but that's not really the issue, because that part is working, like you see in the links i get back. If i hardcode the link inside there it removes the purpose of translating the url. I do it like that for all my links , which work fine. It is when i have a parameter like in this case it has this strange behaviour - Christophvh
Try splitting things up. First test the trans() function on the normal route() function, dd() return values, etc.. I think I'm not able to help you any further :( - Thomas Van der Veen
@ThomasVanderVeen i did try that, each part does their job, only the user()->id gets lost when in the french translation. No problem, thanks anyway! - Christophvh

1 Answers

1
votes

I was looking into the code of that package.

It seems to me if I'm not mistaken, that the logic regarding the translation of URL's is based on the route name, not the route path.

You are using the route path here:

LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ["id" => Auth::user()->id])

But it seems like you should actually use the route name instead, meaning 'account-edit' in this case.