- How do I install laravel-lang/locales in my Laravel project?
- Run `composer require laravel-lang/locales` in your project directory. The package integrates automatically with Laravel’s service container and requires no manual configuration unless you customize the default behavior. Check the [official documentation](https://laravel-lang.com/packages-locales.html) for advanced setup options.
- Does this package replace Laravel’s built-in locale system?
- No, it complements Laravel’s native localization. It provides a curated, maintained dataset of locale metadata (e.g., country names, currency codes) that you can use alongside Laravel’s `trans()`, `locale()`, and validation rules. It’s designed to work seamlessly without breaking existing logic.
- Which Laravel versions does laravel-lang/locales support?
- The package is fully compatible with Laravel 11, 12, and 13. It leverages Laravel’s service container and facades, so it adheres to modern Laravel patterns. For older versions (e.g., Laravel 10), check the [release notes](https://github.com/Laravel-Lang/locales/releases) for compatibility.
- Can I use this for dynamic user locale selection (e.g., dropdowns)?
- Yes. The package includes a `Locales::available()` method to fetch all supported locales, which you can use in Blade templates or API responses. For user-driven selection, pair it with Laravel’s session or middleware to set the active locale dynamically via `Locales::set()`.
- How do I customize or extend the locale data?
- You can override or extend the default locale data by publishing the config file (`php artisan vendor:publish --tag=locales-config`) and modifying the `config/locales.php` file. For advanced use cases, the `Locales::raw()` method provides direct access to the underlying data structure for manual manipulation.
- Will this package slow down my application?
- No, the package is optimized for performance. Locale data is cached by default, and the facade-based API (`Locales::`) adds minimal overhead. Only opt-in methods like `Locales::raw()` may impact performance if used excessively, but these are designed for edge cases like bulk operations.
- How do I handle unsupported locales or fallback chains?
- The package includes a fallback mechanism for unsupported locales. Use `Locales::get($code, $fallback = 'en')` to specify a default locale if the requested one isn’t available. For custom fallbacks, extend the `LocaleData` class or override the `fallback` config value in `config/locales.php`.
- Can I use this package with Laravel’s validation rules?
- Absolutely. The package integrates with Laravel’s validation system. For example, validate a locale code with `Rule::in(array_column(Locales::available()->pluck('code'), 'code'))`. This ensures consistency with the package’s dataset while leveraging Laravel’s built-in validation.
- Is there a way to monitor which locales are most/least used?
- Yes, you can track locale usage by logging calls to `Locales::getCurrent()` or by extending the package to emit events when locales are set. Pair this with Laravel’s logging or analytics tools to gather usage statistics for optimization or compliance reporting.
- What alternatives exist for Laravel locale management?
- Alternatives include manually maintaining locale arrays, using third-party libraries like `symfony/intl`, or custom database-driven solutions. However, `laravel-lang/locales` stands out for its Laravel-native integration, active maintenance by the Laravel Lang community, and alignment with Laravel’s ecosystem (e.g., translations via `laravel-lang/lang`). It’s ideal for teams prioritizing consistency and minimal maintenance.