php-standard-library/locale
PHP Standard Library Locale component providing locale-aware formatting and parsing utilities. Helps handle language/region settings, localized dates, numbers, and other internationalization tasks in PHP apps with a lightweight, straightforward API.
Feature Development:
en_ or xyz).Str::of() or third-party libraries like spatie/laravel-translatable.Accept-Language headers or query parameters (e.g., /api/content?locale=fr_FR) before processing.Roadmap Alignment:
Build vs. Buy:
Use Cases:
en-US → en_US) in users table.{"locale": "invalid"}).Accept-Language headers into Locale objects for request-wide localization.Locale::isValid() in Laravel’s FormRequest classes.Locale::fromString('ja_JP')).Adopt if:
en_US, en-us, EN).if ($locale === 'fr')).Locale::fromString('de_DE')).Look elsewhere if:
App::setLocale('en')) without validation or normalization.Intl, laravel-localization) that already handles locales comprehensively.For Executives:
*"This package solves a hidden technical debt problem: inconsistent locale handling across our app. Right now, locales like en_US, en-us, or EN might be treated differently, leading to bugs in multilingual features or API rejections. By adopting this, we:
en_) are caught early, not in production.For Engineering:
*"This gives us a type-safe Locale value object to replace raw strings everywhere locales are used. Key wins:
Locale::fromString('en_') throws an error instead of silently failing later. Example:
$locale = Locale::fromString(request()->input('locale')); // Fails fast for invalid inputs.
en-US → en_US or EN → en automatically, so we don’t have to write custom logic.// Before: User::where('locale', 'en') or User::where('locale', 'en_US')
// After: User::where('locale', Locale::fromString('en_US')->toString())
setLocale(), trans(), and validation layers. Example middleware:
$locale = Locale::fromString($request->header('Accept-Language', 'en_US'));
app()->setLocale($locale->toString());
Tradeoffs:
Locale type (e.g., in models, config).
Recommendation: Start with validation (e.g., form requests, APIs), then expand to domain models and middleware."*For Design/UX Teams: *"This ensures our app handles languages/regions consistently across all platforms (web, mobile, API). For example:
en_GB, not en-us or EN./content?locale=fr will use fr_FR internally, avoiding confusion with fr.
Impact: Fewer edge cases for localization testing, and a smoother experience for users in non-English markets."*How can I help you explore Laravel packages today?