chinleung/laravel-locales
Add easy locale support to Laravel with simple config and helper functions. Set and get the current locale with locale(), and manage supported locales with locales(), prioritizing app.locales over package config. Supports Laravel 6–13 (versioned).
Add configurations and helpers to make an application support multiple locales.
| Package | Laravel | PHP |
|---|---|---|
| 3.x | 13.x | ^8.3 |
| 2.x | 9.x–12.x | ^8.0 |
| 1.x | 6.x–8.x | ^7.4 |
You can install the package via composer:
composer require chinleung/laravel-locales
By default, the application locales is only going to be en. If your application support other locales, you can either set a app.locales in your config/app.php or publish the configuration file:
php artisan vendor:publish --provider="ChinLeung\LaravelLocales\LaravelLocalesServiceProvider" --tag="config"
Retrieve or update the current locale of the application.
// Alias of app()->getLocale();
locale(); // 'en'
// Alias of app()->setLocale('fr');
locale('fr'); // 'fr'
locale(); // 'fr'
Retrieve or update the supported locales of the application.
Has priority forapp.localesoverlaravel-locales.supported.
locales(); // ['en']
locales(['en', 'fr', 'zh']);
locales(); // ['en', 'fr', 'zh']
locales(['en', 'zh']);
locales(); // ['en', 'zh']
composer test
Please see CHANGELOG for more information what has changed recently.
Please see CONTRIBUTING for details.
If you discover any security related issues, please email hello@chinleung.com instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.
This package was generated using the Laravel Package Boilerplate.
How can I help you explore Laravel packages today?