dev-master
9999999-devA better way to handle multilanguage
BSD-2-Clause
The Requires
- php >=5.3.0
- illuminate/support ~4|~5
by Diego Araujo
laravel language translation multilanguage
Wallogit.com
2017 © Pedro PelĂĄez
A better way to handle multilanguage
The goal of this package is offer a simple way to make a multilanguage for Laravel 4/5., (*2)
Edit composer.json file to require this package., (*3)
"require": {
...
"diego1araujo/locale": "dev-master"
}
Next, run the composer update command:, (*4)
composer update
Open up app/config/app.php, (*5)
Find the providers key and add a new item to the array, (*6)
'Diego1araujo\Locale\ServiceProvider',
Find the aliases key and add a new item to the array, (*7)
'Locale' => 'Diego1araujo\Locale\Facade',
Finally, publish the config file, (*8)
php artisan config:publish diego1araujo/locale
To see which languages are available, open up app/config/packages/diego1araujo/locale/config.php, (*9)
By default, the main language is en (english) and the available item contains the list of languages., (*10)
Of course, feel free to change both of them., (*11)
NOTE: The main language isn't appended in url, only others (from
availableitem)., (*12)
Go to app/lang/[language] and create a new file(s) for each language (Files must have the same name for all languages), (*13)
Like this:, (*14)
English app/lang/en/message.php, (*15)
return array(
'welcome' => 'Welcome to my page',
);
Portuguese app/lang/pt/message.php, (*16)
return array(
'welcome' => 'Bem-vindo Ă minha pĂĄgina',
);
Define the set method as a prefix value in route group, (*17)
Route::group(array('prefix' => Locale::set()), function()
{
Route::get('/', function()
{
return View::make('home');
});
Route::get('example', function()
{
return View::make('example');
});
});
Printing a message, (*18)
Lang::get('message.welcome')
Retrieving the current language, (*19)
Locale::get();
Building url's with the current language, (*20)
Locale::url('about'); // [site-domain]/[current-language]/about
You can use a single route for a multiple language page. I suggest you to place all pages in your file translation., (*21)
English app/lang/en/message.php, (*22)
return array(
'menu-page' => 'Page',
'slug-page' => 'page',
);
Portuguese app/lang/pt/message.php, (*23)
return array(
'menu-page' => 'PĂĄgina',
'slug-page' => 'pagina',
);
Route::group(array('prefix' => Locale::set()), function()
{
Route::get(Lang::get('message.slug-page'), ['as' => 'page', 'uses' => 'HomeController@page']);
}
A better way to handle multilanguage
BSD-2-Clause
laravel language translation multilanguage