How to use Localization in Laravel?. The Complete Laravel Developer Course 2022 [Videos].

Localization feature of Laravel supports different language to be used in application. You need to store all the strings of different language in a file and these files are stored at resources/views directory. You should create a separate directory for each supported language. All the language files should return an array of keyed strings as shown below.


Step 1 − Create 3 files for languages − English, French, and German. Save English file at resources/lang/en/lang.php

Step 2 − Save French file at resources/lang/fr/lang.php.

Step 3 − Save German file at resources/lang/de/lang.php.

Step 4 − Create a controller called LocalizationController by executing the following command.

php artisan make:controller LocalizationController --plain

Step 5 − After successful execution, you will receive the following output −


Step 6 − Copy the following code to file




namespace AppHttpControllers;

use IlluminateHttpRequest;
use AppHttpRequests;
use AppHttpControllersController;

class LocalizationController extends Controller {
   public function index(Request $request,$locale) {
      //sets applications locale
      //Gets the translated message and displays it
      echo trans("lang.msg");

Step 7 − Add a route for LocalizationController in app/Http/routes.php file. Notice that we are passing {locale} argument after localization/ which we will use to see output in different language.


Step 8 − Now, let us visit the different URLs to see all different languages. Execute the below URL to see output in English language.


Step 9 − The output will appear as shown in the following image.

Laravel Internationalization

Step 10 − Execute the below URL to see output in French language.


Step 11 − The output will appear as shown in the following image.

French Example

Step 12 − Execute the below URL to see output in German language


Step 13 − The output will appear as shown in the following image.

German Example

See All

Comments (494 Comments)

Submit Your Comment

See All Posts

Related Posts

Laravel / Blog

How to install Laravel ?

For managing dependencies, Laravel uses composer. Make sure you have a Composer installed on your system before you install Laravel. In this chapter, you will see the installation process of Laravel.
14-Feb-2022 /15 /494

Laravel / Blog

What is Laravel - Application Structure?

The application structure in Laravel is basically the structure of folders, sub-folders and files included in a project. Once we create a project in Laravel, we get an overview of the application structure as shown in the image here.
14-Feb-2022 /15 /494

Laravel / Blog

How to setup Configuration in Laravel?

n the previous chapter, we have seen that the basic configuration files of Laravel are included in the config directory. In this chapter, let us discuss the categories included in the configuration.
14-Feb-2022 /15 /494