Make use of Laravel features and best packages for localization

Laravel localization and multi-language functionality in web

A step by step guide to implement multi-language functionality in your web projects

Amir Yousefi
3 min readJun 30, 2019

--

Laravel made it so easy to implement a multi-language website. You can implement it with Laravel localization and just some tricks. Also, there is plenty of Laravel translation packages which you can use in your project. In this post, I will explain how to implement multi-language functionality.

Creating a multi-language website requires two steps. Firstly, you need to detect user local language setting and change it bu user choice. Secondly, you need to translate messages and strings into user local language, in which we use Laravel localization.

DETECTING AND SETTING USER LOCALE

In order to detect user language setting, we need to create a language middleware. this middleware checks for locale setting in the user session. If there was no locale setting, the middleware sets a default locale setting. Then, it sets system locale by the user session setting.

if(is_null(session('locale')))
{
session(['locale'=> "en"]);
}

--

--

Amir Yousefi
Amir Yousefi

Written by Amir Yousefi

Making Impacts using Information Technology

No responses yet