6

Based on this question I'm trying to translate routes in Laravel 4.2 in english and spanish.

This is my app/routes.php code:

<?php


/*Set up locale and locale_prefix if other language is selected*/
if (in_array(Request::segment(1), Config::get('app.web_config.alt_langs'))) {

    App::setLocale(Request::segment(1));
    Config::set('app.web_config.locale_prefix', Request::segment(1));
}


foreach(Lang::get('routes') as $k => $v) {
    Route::pattern($k, $v);
}

Route::group(array('prefix' => Config::get('app.web_config.locale_prefix')), function()
{
    Route::get('/{revelar_fotos}/',['as' => 'revelado_online', 'uses' => 'WebController@reveladoOnline'], function(){
        return 'pages.revelado_online'.App::getLocale();
    });

});

By clicking on the link I get this error in the url:

http://mywebsite.dev/%7Brevelar_fotos%7D

Instead of:

http://mywebsite.dev/photograph-development

This is my en/routes.php:

<?php

return array(

    'revelar_fotos' => 'photograph-development',
);

And this is my es/routes.php:

<?php

return array(

    'revelar_fotos' => 'revelado-online',
);

Why I returned this error?

Community
  • 1
  • 1
Funny Frontend
  • 3,807
  • 11
  • 37
  • 56

1 Answers1

1

I understand that you problem is with generating the URL http://mywebsite.dev/%7Brevelar_fotos%7D

In the question you only described how you did set up the routing handling and this might work. However generating the link itself is done somewhere else and in there you have not done the substitution.

You must be generating the link something like this

URL::to(trans("revelar_fotos"));

trans("revelar_fotos") will get you the correct path and URL::to() generates full link.

Margus Pala
  • 8,433
  • 8
  • 42
  • 52
  • If you prefer URL::route() instead of URL::to() then you can type in `php artisan route:list` to see possible options. Also please make sure that `trans("revelar_photos")` is translated properly – Margus Pala Apr 27 '15 at 06:37
  • I used a specify a name for my route with the 'as' array key, no sense to translate it as you say – Funny Frontend Apr 27 '15 at 06:48