laravel-lang/http-statuses
Localized HTTP status texts for Laravel apps. Adds translation resources for common status codes, making API errors and responses readable in multiple languages. Install via Composer (dev) and integrate with Laravel’s localization system.
404 Not Found → 404 Página no encontrada in Spanish) without altering core Laravel functionality. It integrates seamlessly with Laravel’s built-in translation system (trans() helper, Lang facade), making it a non-intrusive addition.resources/lang/, config/app.php), requiring no architectural changes.Response, ExceptionHandler), where status messages are frequently surfaced to users (e.g., error pages, API responses).lang/http-statuses.php).response()->json([], 404, ['message' => trans('http-statuses.404')])).418), they won’t be translated unless manually added to lang/http-statuses.php.yi, ak) rely on machine translations; human-reviewed locales (e.g., fr, de) are higher quality.return response()->json(['error' => 'Not Found'], 404))?trans('http-statuses.404'))?Illuminate/Translation (default in Laravel).Illuminate/HTTP (for responses).Illuminate/Foundation (for error handling).composer require laravel-lang/http-statuses).resources/lang/).composer require laravel-lang/http-statuses --dev
php artisan vendor:publish --provider="LaravelLang\HttpStatuses\ServiceProvider" --tag="http-statuses"
resources/lang/vendor/laravel-lang/http-statuses/.resources/lang/{locale}/http-statuses.php (e.g., for Spanish):
return [
'404' => 'Página no encontrada',
// ...
];
trans('http-statuses.404').@error('404')
{{ trans('http-statuses.404') }}
@enderror
return response()->json(['error' => trans('http-statuses.404')], 404);
Illuminate\Foundation\Exceptions\Handler:
public function render($request, Throwable $exception)
{
if ($exception instanceof NotFoundHttpException) {
return response()->view('errors.404', [], 404)
->header('X-Status', trans('http-statuses.404'));
}
}
vendor/laravel-lang/http-statuses/lang/{locale}/http-statuses.php to resources/lang/{locale}/.418):
'418' => 'I\'m a teapot (custom message)',
assertEquals('Página no encontrada', trans('http-statuses.404'))).composer update laravel-lang/http-statuses).fr, de) are backported.resources/lang/{locale}/http-statuses.php exists.trans('http-statuses.404', [], 'vendor') to force vendor fallback.config/app.php:
'locales' => ['en', 'es', 'fr', 'custom-locale'],
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Missing locale file | Falls back to English or vendor/ |
Ensure resources/lang/{locale}/ exists. |
| Translation errors (syntax) | Blank/broken messages | Validate translation files (JSON/YAML). |
| Package update breaks compatibility | Rare (MIT license, minimal API) | Test in staging before production updates. |
| Custom status code not translated | Hardcoded fallback used | Manually add to lang/http-statuses.php. |
vendor:publish).trans('http-statuses.{code}') in responses.How can I help you explore Laravel packages today?