Mahmoud Al-HabashOpen to new projects
  • WorkWork
  • ServicesServices
  • LabLab
  • WritingWriting
  • ContactContact
Amman--:--عربي
Writing/Laravel

Laravel Localization and Translations

Build multilingual applications with Laravel localization.

16 January 20261 min readLaravelاقرأ بالعربية

On this page

  1. Translation Files
  2. Use Translations
  3. Set Locale
  4. Middleware

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

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

Middleware

php
public function handle($request, $next)
{
    App::setLocale(session('locale', 'en'));
    return $next($request);
}
All articles

Keep reading

  • Laravel Action Classes Pattern16 January 20261 min read
  • Laravel Action Classes: Single Responsibility16 January 20261 min read
  • Laravel API Rate Limiting16 January 20261 min read