- How do I install giggsey/locale in a Laravel project?
- Run `composer require giggsey/locale` in your project directory. The package is dependency-free and integrates seamlessly with Laravel’s service container. No additional configuration is needed unless you’re using the facade.
- Does this package work with Laravel’s built-in localization (trans(), App::setLocale())?
- Yes. While it doesn’t replace Laravel’s core localization, it enhances it by providing CLDR-compliant country/region names for dynamic display (e.g., `Locale::getCountryName('US', 'en')` returns 'United States'). Use it alongside `trans()` for hybrid systems.
- Can I use giggsey/locale for form validation (e.g., country dropdowns with human-readable labels)?
- Absolutely. The package includes methods like `getCountryName()` to convert country codes (e.g., 'US') to localized names (e.g., 'United States'). Integrate it with Laravel’s validation rules for user-friendly error messages.
- What Laravel versions does giggsey/locale support?
- The package supports Laravel 8+ (PHP 8.1+) and older versions (e.g., v2.0 for PHP 7.x). Check the [README](https://github.com/giggsey/Locale) for version-specific requirements. Laravel 10+ users should verify PHP 8.2 compatibility.
- How often does the CLDR data update, and will it break my app?
- CLDR data updates are versioned (e.g., v48.1.0). Pin the package version (e.g., `^2.9`) to avoid breaking changes. Major updates may require testing, but the API remains stable. Use `composer update giggsey/locale` cautiously.
- Is giggsey/locale compatible with libphonenumber-for-php for phone number parsing?
- Yes, this package was created to support `libphonenumber-for-php`’s GeoCoder without requiring the PHP `intl` extension. It provides the same CLDR data but as portable PHP arrays, ensuring consistency across environments.
- Can I use this package in a serverless environment (e.g., AWS Lambda)?
- Yes, but note the ~1-2MB payload. For serverless, consider caching CLDR data in Redis or a database to reduce memory usage. The package’s modular API lets you load only the data you need (e.g., `getCountries()`).
- What if I only need country names and not the full CLDR dataset?
- The package is modular. Use methods like `getCountries()` or `getTerritories()` to fetch subsets of data. Avoid loading the full dataset if your app doesn’t need it, reducing memory overhead.
- How do I expose CLDR data to my frontend (Vue/React/Alpine.js)?
- Create a Laravel API endpoint (e.g., `/api/locales`) returning the data from `Locale::getSupportedLocales()`. Use Laravel’s API resources or JSON responses. For Livewire, bind the data directly to components.
- Are there alternatives to giggsey/locale for CLDR data in Laravel?
- Alternatives include the PHP `intl` extension (if available) or packages like `symfony/intl` (requires CLDR data files). However, giggsey/locale is unique in bundling up-to-date CLDR as native PHP arrays without extension dependencies.