laravel-lang/lang
Community-maintained Laravel translation files for many locales. Adds localizations for core messages and validation, with easy Composer install and ongoing updates. Part of the Laravel Lang ecosystem; see docs for setup and contribution guidelines.
Installation:
composer require laravel-lang/lang --dev
Add the package to your composer.json under require-dev to avoid bloating production builds.
Publish Assets:
php artisan vendor:publish --provider="LaravelLang\Lang\LangServiceProvider" --tag=lang
This publishes language files to resources/lang/vendor/laravel-lang/.
Update config/app.php:
Add the package's service provider to the providers array:
LaravelLang\Lang\LangServiceProvider::class,
First Use Case: Use the translations in your Blade templates or PHP code:
@lang('vendor.laravel-lang::auth.passwords.reset')
Or in PHP:
__('vendor.laravel-lang::auth.passwords.reset');
Namespace Handling:
vendor.laravel-lang:: to avoid conflicts.vendor.laravel-lang::validation.attributes.name for validation messages.Integration with Laravel Breeze/Jetstream:
@lang('vendor.laravel-lang::auth.login')
Validation Messages:
$rules = ['email' => 'required|email'];
$messages = [
'email.required' => __('vendor.laravel-lang::validation.required', ['attribute' => 'Email']),
];
Dynamic Language Switching:
public function handle($request, Closure $next) {
app()->setLocale($request->header('Accept-Language') ?? config('app.locale'));
return $next($request);
}
Customizing Translations:
resources/lang/{locale}/vendor/laravel-lang/.auth.login in resources/lang/fr/vendor/laravel-lang/auth.php:
return [
'login' => 'Connexion',
];
Partial Overrides:
php artisan vendor:publish --provider="LaravelLang\Lang\LangServiceProvider" --tag=lang --force
Then manually edit the files you need.Localization for Pagination:
{{ $users->appends(request()->query())->links('vendor.laravel-lang::pagination.default') }}
Testing Localizations:
$this->app->setLocale('fr');
$this->withoutExceptionHandling();
Custom Language Files:
Namespace Conflicts:
vendor.laravel-lang to prevent overwrites during updates.app.laravel-lang) for custom overrides.Missing Translations:
zu, uz_Cyrl) have partial translations. Check the status page before relying on them.zu (Zulu) has 19 missing entries; use fallback locales if needed:
__('vendor.laravel-lang::auth.login', [], 'en'); // Fallback to English
Performance:
php artisan vendor:publish --provider="LaravelLang\Lang\LangServiceProvider" --tag=lang --langs="fr,es,de"
Validation Quirks:
encoding validation rule may have inconsistencies (e.g., az, fr, vi languages). Override these in your custom files:
'validation' => [
'attributes' => [
'encoding' => 'kódolás',
],
'custom' => [
'encoding' => [
'encoding' => 'A :attribute megnévezett kódolásban kell lennie.',
],
],
],
Jetstream/Breeze Compatibility:
Verify your email address) may have missing translations in certain languages (e.g., fr, az). Test thoroughly.Check Loaded Translations:
dd(__path('vendor.laravel-lang::auth.login'));
This helps verify if the translation is loaded or falling back to English.
Clear Compiled Views: If translations aren’t updating, clear the view cache:
php artisan view:clear
Locale-Specific Issues:
php artisan lang:list to list available locales.app()->setLocale('fr');
Contributing Fixes:
Custom Language Files:
resources/lang/vendor/laravel-lang/custom/
├── custom.php
└── validation.php
Dynamic Language Loading:
FileLoader:
$loader = app('translator')->getLoader();
$loader->addNamespace('laravel-lang', resource_path('lang/vendor/laravel-lang'));
API Localization:
Accept-Language header in API requests and use middleware to set the locale:
public function handle($request, Closure $next) {
$locale = substr($request->header('Accept-Language'), 0, 2);
app()->setLocale($locale);
return $next($request);
}
Fallback Logic:
config/app.php:
'fallback_locales' => ['en', 'fr'],
How can I help you explore Laravel packages today?