根据前缀/会话在Laravel中加载lang文件

根据前缀/会话在Laravel中加载lang文件,laravel,translation,Laravel,Translation,我用3种语言建立了一个多语言网站(mk-默认,sq和en),并在routes.php中生成了以下代码: $languages = array('en', 'sq'); $locale = Request::segment(1); if(in_array($locale, $languages)){ \App::setLocale($locale); }else{ $locale = null; } // Set the session here Session::put('loc

我用3种语言建立了一个多语言网站(mk-默认,sqen),并在routes.php中生成了以下代码:

$languages = array('en', 'sq');
$locale = Request::segment(1);
if(in_array($locale, $languages)){
    \App::setLocale($locale);
}else{
    $locale = null;
}
// Set the session here
Session::put('locale', $locale);

Route::group(array('prefix' => $locale), function()
{
    Route::get('/', array('as' => 'home', 'uses' => 'Controllers\Frontend\FrontendController@getIndex'));
    // .... other routes
});
我的默认语言环境是'mk',在Land文件夹中还有另外两种语言,sqen。 虽然路由工作正常,但问题在于加载lang文件时。它适用于app.php中设置的默认语言mken,但不会切换为sq翻译,而是加载enlang文件

例如:

  • URL:加载mklang文件

  • URL:加载enlang文件

  • URL:加载enlang文件,而不是sq问题:根据前缀/会话在Laravel中加载lang文件“

    @帕特的回答(在评论中)解决了我的问题()


    简言之,使用eases可与Lavarel一起创建多语言网站。

    为什么不使用这样的工具:谢谢,这是可以预期的。最好将该评论作为答案发布,并将其作为问题的解决方案?因为这是一个合法的答案,从我的角度来看(有同样的问题,现在使用该软件包)。@Alomvar我怎么能做到?我只能对Pat的评论投赞成票,更多信息请参见。它应该像在其他地方回答问题一样简单,只需在问题页面的底部写一个答案。(我会自己发布答案,但这将盗取@Pat提供最佳解决方案的声誉)。
    {{{ URL::route('home') }}}
    
    public function getIndex($locale = null)
    {
    
        $data = array();
        return View::make('frontend.frontpage', $data);
    }