1

Using the following package: laravel-localization .

I am translating the routes and followed the steps, they all work fine for routes without variables, but i'm stuck on how i should send my variables inside my views.

Link inside my view :

<a href="{{ LaravelLocalization::localizeURL(trans('routes.account-edit')) }}"> 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');

});

I tried just adding it inside the route as array like below, but i can't get it working.

<a href="{{ LaravelLocalization::localizeURL(trans('routes.account-edit'), ['id' => $user->id]) }}"> Edit Link</a>
Christophvh
  • 12,586
  • 7
  • 48
  • 70
  • Not using the library myself, but according to the code at https://github.com/mcamara/laravel-localization/blob/master/src/Mcamara/LaravelLocalization/LaravelLocalization.php, method localizeURL takes in $url and $locale as its parameter, which means that passing in 2nd parameter like you did definitely won't work. Can you try using method getLocalizedURL? LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ['id' => $user->id]) – SteD Sep 01 '16 at 07:46
  • @SteD , damn. the funny thing is that i tried that method but not added the first value as NULL. This makes total sense. You can post that as an answer and i will accept it! Thank you very much! – Christophvh Sep 01 '16 at 07:53
  • alright, glad it helps =] – SteD Sep 01 '16 at 07:55

1 Answers1

1

Not using the library myself, but according to the code at the github repo, method localizeURL takes in $url and $locale as its parameter, which means that passing in 2nd parameter like you did definitely won't work.

Can you try using method getLocalizedURL?

LaravelLocalization::getLocalizedURL(null, trans('routes.account-edit'), ['id' => $user->id])
SteD
  • 13,909
  • 12
  • 65
  • 76