Laravel

Laravel Localization and Translations

January 16, 2026 1 min read 44 views

Localization in Laravel:

Translation Files

// lang/en/messages.php
return [
    'welcome' => 'Welcome, :name!',
];

// lang/ar/messages.php
return [
    'welcome' => 'مرحباً، :name!',
];

Use Translations

__('messages.welcome', ['name' => 'John']);
@lang('messages.welcome', ['name' => 'John'])

Set Locale

App::setLocale('ar');
$locale = App::getLocale();

Middleware

public function handle($request, $next)
{
    App::setLocale(session('locale', 'en'));
    return $next($request);
}
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!