Reputation: 2663
I build a multilanguage site with 3 languages (mk - default, sq and en) and ended up with the following code in 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
});
My default locale is 'mk' and I also have 2 other languages in Land folder, sq and en. While the routing works fine, problem is when loading lang files. It works for default language mk set in app.php and for en but won't switch for sq translation, and instead it loads the en lang files.
Example:
URL: http://website.com loads mk lang files
URL: http://website.com/en loads en lang files
URL: http://website./sq loads en lang files instead of sq <--- PROBLEM
Among other code, I have the following in the view:
{{{ URL::route('home') }}}
The controller is usual:
public function getIndex($locale = null)
{
$data = array();
return View::make('frontend.frontpage', $data);
}
My question: why the sq language files aren't loaded when the URI parameter is changed to sq?
Upvotes: 0
Views: 2835
Reputation: 2663
Question: "Loading lang files in Laravel depending on prefix/session"
@Pat's answer (in comment) solved my issue (Loading lang files in Laravel depending on prefix/session)
In short, using https://github.com/mcamara/laravel-localization eases creating multilangugage website with Lavarel.
Upvotes: 2