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?
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.