Wallogit.com
2017 © Pedro Peláez
Multi language for Laravel 5.3+
Multi language for Laravel 5.3+, (*1)
composer require aharen/language, (*2)
Add the service provider to providers array in config/app.php, (*3)
aharen\Language\LanguageServiceProvider::class,, (*4)
Add the facade to aliases array in config/app.php, (*5)
'Language' => 'aharen\Language\Facades\Language::class',, (*6)
Run vendor:publish artisan command to publish the database migration file and the default seeder, (*7)
php artisan vendor:publish, (*8)
Now add the DefaultLanguageSeeder to database/DatabaseSeeder.php, (*9)
$this->call(DefaultLanguageSeeder::class);, (*10)
You might need to run composer dumpautoload for the seeder to start working, (*11)
Optional The provided seeder will create English as the default language but you can change the seeder to any language you like., (*12)
In addition you will have to update locale and fallback_locale in config/app.php to your desired default language, since the package uses these to maintain set locale and default locale., (*13)
This will enable the use of Laravels default localization methods and directives such as 'echo trans('messages.welcome');and@lang('messages.welcome'). You can store your translations in the defaultresources/lang` directory., (*14)
You should add a route prefix to your routes in one of the following ways:, (*15)
In your routes file to the route group, (*16)
Route::group(['prefix' => \App::getLocale()], function () {
// your routes here
});
Or you can modify mapWebRoutes() method in App\RouteServiceProvider as follows:, (*17)
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
'prefix' => \App::getLocale(),
], function ($router) {
require base_path('routes/web.php');
});