dongrim/laravel-localization is a Laravel package for easy localization for laravel.
It currently has 0 GitHub stars and 5 downloads on Packagist (latest version v1.0.1).
Install it with composer require dongrim/laravel-localization.
Discover more Laravel packages by dongrim
or browse all Laravel packages to compare alternatives.
Last updated
Easy i18n localization for Laravel.
The package offers the following:
Laravel | laravel-localization :-------------|:---------- 6.0-9.x (PHP 7 required) | 1.0.x
Install the package via composer: composer require dongrim/laravel-localization
In order to edit the default configuration you may execute:
php artisan vendor:publish --provider="Dongrim\LaravelLocalization\LaravelLocalizationServiceProvider"
After that, config/localization.php will be created.
The configuration options are:
You may register the package middleware in the app/Http/Kernel.php file:
<?php namespace App\Http;
use Illuminate\Foundation\Http\Kernel as HttpKernel;
class Kernel extends HttpKernel {
/**
* The application's route middleware.
*
* @var array
*/
protected $routeMiddleware = [
/**** OTHER MIDDLEWARE ****/
'localize' => \Dongrim\LaravelLocalization\Middleware\LocalizationMiddleware::class,
];
}
Add the following to your routes file:
// routes/web.php
Route::group([
'prefix' => Localization::prefix(),
'middleware'=>['localize']
], function(){
/** ADD ALL LOCALIZED ROUTES INSIDE THIS GROUP **/
Route::get('/', function(){
return View::make('welcome');
})->name('welcome');
Route::get('test',function(){
return View::make('test');
})->name('test');
});
/** OTHER PAGES THAT SHOULD NOT BE LOCALIZED **/
If you want to use the list of locales from the database change config/localization.php .
For example:
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Dongrim\LaravelLocalization\Traits\Localizable;
use Dongrim\LaravelLocalization\Contracts\Localization as LocalizationContract;
class Localization extends Model implements LocalizationContract
{
use Localizable;
}
Use named routes for more an easy way to access url localization.
<a href="route('welcome')">Welcome</a>
<a href="route('test')">Test</a>
A locale other than the default locale will be automatically added to the url
// when current locale en and default locale en
http://site.com/
http://site.com/test
// when current locale es and default locale en
http://site.com/es
http://site.com/es/test
This package comes with helpers.
List of all available locales
<ul>
@foreach(locales() as $locale)
{{ $locale }}
@endforeach
</ul>
When you set useAcceptLanguageHeader = true, to find out the default language you need to use
@dump(default_locale())
To cache your routes, use:
php artisan route:clear