To implement multilingual support in Laravel, you can follow the steps outlined below. This guide covers both dynamic translations (admin input) and static inline text translations.
Dynamic Translations
Dynamic translations involve storing translated content in your database and retrieving it based on the current language setting.
1. Set Up Language Routes
Create routes to switch between different languages:
php1use Illuminate\Support\Facades\Route; 2 3Route::get('/lang/{lang}', function ($lang) { 4 if (!in_array($lang, ['en', 'id'])) { 5 $lang = 'id'; // Default language 6 } 7 session(['locale' => $lang]); 8 app()->setLocale($lang); 9 return back(); 10});
2. Create Language Middleware
Ensure that the current locale is set for each request:
php1use Illuminate\Support\Facades\App; 2use Closure; 3 4class SetLanguageMiddleware 5{ 6 public function handle($request, Closure $next) 7 { 8 if (session()->has('locale')) { 9 App::setLocale(session('locale')); 10 } else { 11 App::setLocale(config('app.locale')); // Default language in config/app.php 12 } 13 return $next($request); 14 15[Read the full article at DEV Community](https://dev.to/raflizocky_/laravel-localization-multi-language-website-2hk9) 16 17--- 18 19**Want to create content about this topic?** [Use Nemati AI tools](https://nemati.ai) to generate articles, social posts, and more.

![[AINews] The Unreasonable Effectiveness of Closing the Loop](/_next/image?url=https%3A%2F%2Fmedia.nemati.ai%2Fmedia%2Fblog%2Fimages%2Farticles%2F600e22851bc7453b.webp&w=3840&q=75)



