Courses

Multi-Language Laravel 11: All You Need to Know

Language Switcher from URL

You're reading a FREE PREVIEW of a PREMIUM course.
Summary of this lesson:
- Configure available locales in app configuration
- Create SetLocale middleware to handle language switching
- Modify routes to include locale segment
- Add language selector to navigation views
- Handle redirects and authentication with locales

Adding a language selector is crucial to any multilingual application. In this practical example, we'll add a language selector to our navigation bar:

In this first example, we will define the language from the URL segment, like /en/about or /es/register.


Setup

Here's our plan to set up a language selector:

  • Configuration: add a language list to the config - this will be used to display the language selector
  • Middleware: Add a Middleware to handle language change and URL redirection
  • Routes: Modify Routes to use the Middleware
  • Views: Add a language selector to our Views
  • Redirects: Modify our redirects for authentication

Let's start with the configuration:...

The full lesson is only for Premium Members.
Want to access all 18 lessons of this course? (80 min read)

You also get:

  • 76 courses
  • Premium tutorials
  • Access to repositories
  • Private Discord