Multilingual Web Application with Laravel:
We will implement a way for users to choose a language that they want.
In the previous tutorial, you have learned how to change your application locale and provide translated content. In this tutorial you will learn how to enable users to change the language of the website.
There are actually two ways of doing this:
- building the feature yourself
- using a package
Creating a language switcher is very simple and you could probably write it yourself. The whole process would go like this. Have a config file with languages supported, look for the locale in the URL, call
\App::setLocale('hr'); depending on the locale found in the URL. There ain't much to it.
With some failures along the way, you could probably pull it off. I have tried doing so in Laravel 4.2 and have burned myself in the end. Since then I have switched to using a package mcamara/laravel-localization.
In this tutorial, we will use the above-mentioned package to provide a language switcher, have routes that can be translated and routes that do not need to be translated.
To continue reading, choose a subscription plan: