【发布时间】:2014-06-20 02:52:38
【问题描述】:
我用 3 种语言(mk - 默认,sq 和 en)构建了一个多语言网站,并最终在路由中使用以下代码.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 文件夹中还有 2 种其他语言,sq 和 en。 虽然路由工作正常,但问题是在加载 lang 文件时。它适用于 app.php 中设置的默认语言 mk 和 en 但不会切换到 sq 翻译,而是加载 en 语言文件。
例子:
URL:http://website.com 加载 mk 语言文件
网址:http://website.com/en 加载 zh 语言文件
URL:http://website./sq 加载 en 语言文件而不是 sq
在其他代码中,我在视图中有以下内容:
{{{ URL::route('home') }}}
控制器是常用的:
public function getIndex($locale = null)
{
$data = array();
return View::make('frontend.frontpage', $data);
}
我的问题:为什么当 URI 参数更改为 sq 时,没有加载 sq 语言文件?
【问题讨论】:
-
为什么不使用这样的东西:github.com/mcamara/laravel-localization
-
谢谢,按预期工作
-
最好将该评论发布为答案并接受它作为问题的解决方案?因为这是一个合法的答案,从我的角度来看(有同样的问题,现在使用那个包)。
-
@Alomvar 我该怎么做?我只能对 Pat 的评论投赞成票
-
请参阅stackoverflow.com/help/self-answer 了解更多信息。它应该像在其他地方回答问题一样简单,只需在问题页面的底部写一个答案。 (我会自己发布答案,但这会窃取@Pat 实际提供最佳解决方案的声誉)。
标签: laravel translation