akaunting/laravel-language is a Laravel package for language switcher package for laravel.
It currently has 223 GitHub stars and 328.240 downloads on Packagist (latest version 2.0.0).
Install it with composer require akaunting/laravel-language.
Discover more Laravel packages by akaunting
or browse all Laravel packages to compare alternatives.
Last updated
This package allows switching locale easily on Laravel projects. It's so simple to use, once it's installed, your App locale will change only by passing routes into SetLanguage middleware.
| Laravel | PHP | Package | |---------|-----------|---------| | 5.8 | 7.2 - 7.4 | ^2.0 | | 6.x | 7.2 - 8.0 | ^2.0 | | 7.x | 7.2 - 8.0 | ^2.0 | | 8.x | 7.3 - 8.1 | ^2.0 | | 9.x | 8.0 - 8.2 | ^2.0 | | 10.x | 8.1 - 8.3 | ^2.0 | | 11.x | 8.2 - 8.4 | ^2.0 | | 12.x | 8.2 - 8.5 | ^2.0 |
Top features:
Run the following command:
composer require akaunting/laravel-language
Note: Laravel 5.5+ automatically discovers the package. Manual registration is only needed for older versions.
For Laravel < 5.5, register the service provider in config/app.php:
Akaunting\Language\Provider::class,
Add alias if you want to use the facade:
'Language' => Akaunting\Language\Facade::class,
Publish config, migration and blade files.
php artisan vendor:publish --tag=language
Optional: Publish flag images for customization (only if you want to replace flag images):
php artisan vendor:publish --tag=language-flags
This will copy flag images to public/vendor/language/flags/ where you can replace them with your custom flags. The package will automatically use your custom flags if they exist, otherwise it will use the default package flags.
Add locale column to users table:
php artisan migrate
Default values can be modified also on config/language.php
All routes in which you want to set language should be under the language
middleware to set at each request to App locale.
Route::group(['middleware' => 'language'], function () {
// Here your routes
});
Tip: /languages prefix can be changed from config/language.php
Returns an array with [$code => $name] for all allowed
languages of config. Example usage on blade:
@foreach (language()->allowed() as $code => $name)
<a href="{{ language()->back($code) }}">{{ $name }}</a>
@endforeach
Returns an output with flags for all allowed languages of config.
Output can be changed from resources/views/vendor/language folder
Returns the flag of the current locale.
Output can be changed from resources/views/vendor/language folder
Get an array like [$code => $name] from an array of only $codes.
Get an array like [$name => $code] from an array of only $langs.
Returns the URL to set up language and return back: back()
Also if you prefer to use directly route() function you can use it as following code:
{{ route('language::back', ['locale' => $code]) }}
Returns the URL to set language and return to home: url('/')
Also if you prefer to use directly route() function you can use it as following code:
{{ route('language::home', ['locale' => $code]) }}
Returns the language name of $code if specified or the current
language set if not.
Tip: Use app()->getLocale() to get the current locale
Returns the language code of $name if specified or the current
language set if not.
Please see Releases for more information what has changed recently.
Pull requests are more than welcome. You must follow the PSR coding standards.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see LICENSE for more information.