2016-11-30 177 views
-1

這是一個非常奇怪的情況。我的一些路線不想翻譯。我正在使用Laravel mcamara/laravel-localization軟件包。Laravel路線翻譯問題

路線按照文檔中的描述進行翻譯。 在我的網站上,每個翻譯都有一個標誌來改變語言。通過懸停在標誌上,它僅更改語言,但不會轉換路線。奇怪的是,它對於某些路線起作用,但對於一些路線而言,我無法找出什麼是邏輯。

例如,我有一個顯示文章的控制器。這裏是路線:

Route::get(LaravelLocalization::transRoute('routes.artciles').'/{id}/{slug}.html', ['as' => 'strategy.show', 'uses' => '[email protected]']); 
Route::get(LaravelLocalization::transRoute('routes.artciles').'/{category}.html', ['as' => 'strategy.category', 'uses' => '[email protected]']); 
Route::get(LaravelLocalization::transRoute('routes.artciles').'.html', ['as' => 'strategy.index', 'uses' => '[email protected]']); 

這裏它沒有翻譯路線?

將鼠標懸停我看到的只是:中

en/articles.htmlde/articles.html代替en/articles.htmlde/artikel.html

+0

不要在'LaravelLocalization :: transRoute('routes.artciles')'中輸入錯誤嗎?你不是說'routes.articles'嗎? –

+0

不幸的不是。在lang/routes.php它也是相同的錯字:( –

回答

0

我找到了解決方案。這是人誰也有類似的問題:在HTTP/routes.php文件

的代碼必須是無參數:

Route::get(LaravelLocalization::transRoute('routes.article'), ['as' => 'strategy.show', 'uses' => '[email protected]'])->where(['id' => '[0-9]+']); 
Route::get(LaravelLocalization::transRoute('routes.article_cat'), ['as' => 'strategy.category', 'uses' => '[email protected]']); 
Route::get(LaravelLocalization::transRoute('routes.articles'), ['as' => 'strategy.index', 'uses' => '[email protected]']); 

而在郎/ routes.php文件可以包含這樣的參數:

'articles' => 'help.html', 
'article' => 'help/{id}/{slug}.html', 
'article_cat' => 'help/{category}.html',