Another example of how we can add a language selector to our application is by using sessions and a DB table to store the user's preferred language.
This example will not use a URL to determine the language which will allow us to use the same URL for all languages.
Setup
Our setup process for Database stored language selection will touch these things:
- Configuration: Adding a language list to our configuration - this will be used to display the language selector
-
DB Structure: Creating a new field on the
users
table calledlanguage
- Controller: Create a controller that will handle the language change
- Middleware: Add a middleware to handle language settings based on user's preferences
- Views: Adding a language selector to our views
- Routes: Adding a route that will allow us to change the language
Let's start with the configuration:...