Home - Scripts - Website Development
Laravel i18n lets apps support 2+ languages, switch locales via the URL, and load translations instantly from JSON files.
Key Points
Internationalization (i18n) is essential for modern web applications that aim to reach a global audience. Laravel, one of the most popular PHP frameworks, includes a powerful localization system that makes it easy to support multiple languages.
In this guide, we’ll implement multi-language support in Laravel 12 using JSON language files and route-based locale switching. This tutorial is ideal if you want to hire Laravel developers for your next project or need custom web development for multilingual websites.
i18n stands for Internationalization. It enables your application to display content in multiple languages based on the user’s preference.
Example:
|
Language |
Text |
|
English |
Welcome |
|
Hindi |
स्वागत है |
Laravel provides a built-in localization system that we will leverage. Whether you are offering website development services or building a multilingual platform for your business, i18n is a must-have feature.
We will create a Laravel 12 app that allows users to:
This method is simple, clean, and beginner-friendly, making it ideal for companies looking to hire Laravel developers or enhance their website development services.
Open config/app.php and check the locale configuration:
This sets English (en) as the default language. You can change it to any language as needed. A proper default ensures that your custom web development projects work seamlessly across multiple locales.
Laravel supports JSON-based translations, which are easier to manage for smaller projects.
English translations: resources/lang/en.json
Hindi translations: resources/lang/hi.json
Each key corresponds to a text string that will appear in your application. This approach is widely used by top web development companies to simplify translation management.
Middleware is used to detect the language from the URL and set the locale accordingly.
Run the following command:
Edit app/Http/Middleware/SetLanguage.php:
The middleware checks the {lang} parameter in the URL and sets the application locale. This is a key step for custom web development projects that require dynamic language support.
Unlike previous versions, Laravel 12 uses bootstrap/app.php to register middleware rather than Kernel.php.
Edit bootstrap/app.php:
The setlang alias makes it easy to use the middleware in route groups. This is a standard practice used by top web development companies to streamline custom web development.
Next, define routes that include a language prefix {lang}.
Edit routes/web.php:
The {lang} segment in the URL determines the selected language. This URL-based approach is simple for developers and end-users.
Example URLs:
English: /en/home
Hindi: /hi/home
This structure is commonly used by web development companies offering website development services in multiple languages.
Create a Blade view at resources/views/home.blade.php:
__('key') fetches translated text from JSON files. This makes it easy to manage multiple languages for custom web development projects.
After adding or modifying JSON language files or routes, clear Laravel caches:
Clearing caches ensures that the latest translations and route changes are applied. This is a standard best practice among Laravel developers.
Open your browser and check the following URLs:
English: http://127.0.0.1:8000/en/home → Displays Welcome / Home
Hindi: http://127.0.0.1:8000/hi/home → Displays स्वागत है / होम
Your multilingual setup is working perfectly. This is the kind of feature custom web development companies implement for clients' projects.
Middleware: Controls the application locale based on the URL.
JSON Files: The simplest way to manage translations for custom web development.
Routes: The {lang} prefix enables language switching.
__() Helper: Fetches translations in Blade views.
Cache Clearing: Always clear caches after adding new languages or changing translations.
With this setup, you now have a fully functional multilingual Laravel 12 application. This is ideal if you plan to hire Laravel developers or offer website development services that require multilingual support.
©2026Digittrix Infotech Private Limited , All rights reserved.