作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
基于此question我正在尝试用英语和西类牙语翻译 Laravel 4.2 中的路线。
这是我的 app/routes.php 代码:
<?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();
});
});
通过单击链接,我在 url 中收到此错误:
http://mywebsite.dev/%7Brevelar_fotos%7D
代替:
http://mywebsite.dev/photograph-development
这是我的 en/routes.php:
<?php
return array(
'revelar_fotos' => 'photograph-development',
);
这是我的 es/routes.php:
<?php
return array(
'revelar_fotos' => 'revelado-online',
);
为什么我返回这个错误?
最佳答案
我知道您的问题在于生成 URL http://mywebsite.dev/%7Brevelar_fotos%7D
在问题中,您只描述了如何设置路由处理,这可能会奏效。然而,生成链接本身是在其他地方完成的,在那里你还没有完成替换。
您必须生成类似这样的链接
URL::to(trans("revelar_fotos"));
trans("revelar_fotos")
将为您提供正确的路径,URL::to()
生成完整链接。
关于php - 如何在 Laravel 中翻译路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29888415/
我是一名优秀的程序员,十分优秀!