giggsey/locale
Up-to-date Unicode CLDR locale data packaged as native PHP arrays. Created to avoid requiring the PHP intl extension and to provide newer locale data than many operating systems ship. Used primarily by libphonenumber-for-php (GeoCoder support).
intl extension, which is often unavailable in shared hosting.trans() and locale() systems with dynamic, CLDR-compliant region names.Rule::in(['US', 'CA']) → "United States, Canada").libphonenumber-for-php for phone number parsing/formatting (e.g., E.164, region-specific validation).de locale).Locale::getCountryName('US', 'en'); // "United States"
Locale::getSupportedLocales(); // Array of locale codes
are intuitive and Laravel-friendly.countries table with CLDR data for queryable regions.US → United States) in validation, APIs, and UI.^2.9) is mandatory to avoid breaking changes if the underlying data structure evolves.getCountries() vs. getTerritories()).composer update giggsey/locale).intl extension dependencies?App::setLocale(), trans(), and config('app.locale').FormRequest rules.@php echo Locale::getCountryName($user->country); @endphp).libphonenumber-for-php: Prerequisite for phone number parsing/formatting.spatie/laravel-translatable: Use CLDR data for fallback locales.laravel-excel: Region-specific data exports with standardized names.composer require giggsey/locale:^2.9
2.9.x) to avoid auto-updates.// app/Providers/AppServiceProvider.php
public function boot()
{
$this->app->singleton('locale', function () {
return new \Giggsey\Locale\Locale();
});
}
// app/Facades/LocaleFacade.php
public static function getCountryName(string $code, string $locale = 'en'): string
{
return app('locale')->getCountryName($code, $locale);
}
Register the facade in config/app.php.// database/seeders/CountrySeeder.php
use Giggsey\Locale\Locale;
public function run()
{
$locale = new Locale();
foreach ($locale->getCountries() as $code => $data) {
DB::table('countries')->updateOrCreate(
['code' => $code],
['name' => $data['en']['displayName']]
);
}
}
// app/Providers/AppServiceProvider.php
public function boot()
{
Cache::remember('cldr_countries', now()->addYear(), function () {
return (new Locale())->getCountries();
});
}
vendor/autoload.php is included in Laravel’s autoloader.intl extension required, making it ideal for environments where extensions are restricted.LocaleHelper trait for reusable methods in controllers/services.countries table)./api/locales) for SPAs.getCountries() returns expected keys).^2.9).getCountries() returns expected keys).How can I help you explore Laravel packages today?