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).
Architecture fit:
The laravel-locales package provides a minimalist, config-centric solution for multilingual Laravel applications, leveraging Laravel’s native localization APIs while abstracting boilerplate. Its facade-based helpers (locale(), locales()) and config-first approach align well with Laravel’s conventions, making it ideal for projects requiring basic-to-moderate locale management (e.g., language switchers, locale-aware routing, or UI labels). The package’s modular design (service provider, published config) enables easy integration without invasive changes to existing codebases.
Key strengths:
app()->setLocale() and app()->getLocale(), reducing learning curves.['en', 'fr']) and associative arrays (['en' => 'English']), accommodating UI and backend needs./es/blog).Limitations:
spatie/laravel-translatable) if both modify app()->setLocale().Technical risk:
/xx/blog → /en/blog) be implemented? Is this configurable or requires custom logic?php artisan route:cache) or Octane? How are these tested?Stack fit: The package is fully compatible with Laravel 13’s core systems:
Route::prefix('{locale}')).SetLocaleMiddleware).config/locales.php file, aligning with Laravel’s config-first philosophy.App facade (locale(), locales()), enabling concise syntax without polluting the global namespace.Unverified compatibility:
spatie/laravel-translatable) if both modify app()->setLocale() or app()->getLocale().Migration path:
composer require chinleung/laravel-locales:^3.0
php artisan vendor:publish --provider="ChinLeung\LaravelLocales\LaravelLocalesServiceProvider" --tag="config"
config/app.php to define supported locales:
'locales' => [
'en' => 'English',
'fr' => 'Français',
'es' => 'Español',
],
config/locales.php for custom logic (e.g., default locale, fallbacks).// Before
app()->setLocale('fr');
// After
locale('fr');
locales() helper to manage supported locales dynamically:
locales(['en', 'fr']); // Update globally
Route::middleware(['set-locale'])->group(function () {
Route::get('/blog', [BlogController::class, 'index']);
});
SetLocaleFromRoute).mix.js('resources/js/locales/fr.js', 'public/js/fr.js')).Sequencing:
Maintenance:
Support:
spatie/laravel-translatable or laravel-localization if more features are needed.Scaling:
locale(), locales()) add negligible runtime cost.php artisan route:cache).Cache::remember()) if dynamic updates are rare.Failure modes:
app()->setLocale(), behavior may be unpredictable.php artisan route:cache if not handled dynamically.How can I help you explore Laravel packages today?