illuminate/translation
Illuminate Translation is Laravel’s translation engine, providing a Translator with loaders, language files, and fallback locales to resolve strings and pluralization. Supports namespaces, JSON translations, and runtime locale switching for multilingual PHP apps.
Start inside a Laravel app — this package is not meant to be installed standalone (it’s a subtree split of laravel/framework). First steps:
resources/lang/{locale}/{group}.php (e.g., resources/lang/en/validation.php).__('validation.required') or trans('validation.required') in Blade, controllers, or services.app()->setLocale('es') (often in middleware or user preferences).auth.php, admin/dashboard.php) — keeps files lean and scannable.:variable syntax ('welcome' => 'Hello, :name') and pass replacements: __('greeting.welcome', ['name' => 'Alex']).// Explicit rules
'comments' => '{0} No comments|[1,*] :count comments',
// Simple Countable (Laravel auto-selects form based on :count)
'apples' => 'There are :count apples',
Resolve with trans_choice('apples', $count, ['count' => $count]).config('app.fallback_locale') to avoid broken UI (e.g., 'fallback' => 'en').lang/vendor/{package}/{locale}/{file}.php to patch package translations (e.g., Filament, Spatie packages).__() helper or Lang facade — direct Translator class usage is rare.composer require illuminate/translation. Use laravel/framework instead.php and json translation files per group (e.g., lang/en/auth.php + lang/en/auth.json → undefined behavior). Choose one format.en-US ≠ en-us by default. Normalize in middleware:
app()->setLocale(Str::lower(str_replace('_', '-', $locale)));
APP_DEBUG=true), missing keys render as ???key.name??? — makes gaps obvious.php artisan translation:export (Laravel 11+) to cache all translations for production speed.Lang::get() in loops — fetch entire group once (Lang::get('messages')) or pre-load used keys.Translator + TranslationLoader to power translations from database, APIs, or CMS (e.g., Laravel’s Lang facade accepts custom loader via Lang::extend()).How can I help you explore Laravel packages today?