gpt4 book ai didi

php - 如何在 Laravel 中翻译路由?

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:47:26 25 4
gpt4 key购买 nike

基于此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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com