Answer the question
In order to leave comments, you need to log in
Multilingual site on Laravel 7, how to implement?
Implemented the language change itself.
Middleware checks if the URL contains the language directory. If it is, then App::setLocale($locale) is set and the page is loaded.
When changing the language, I edit the URL, at the beginning of the link I substitute the directory corresponding to the selected language.
When changing the language, a cookie is written with the language value.
All Route combined into a group.
I stopped at the moment when the language value in the cookie is not equal to the directory language value (this can happen when the user changed the language, but later returned to the site using the old link corresponding to another language).
I wanted to do a redirect if the cookie and language were different in the url. But the redirect will not save setLocale and an infinite loop is obtained. Maybe in $next($request) it is somehow possible to pass other URL values? But most likely this is my sick fantasy)
How to implement a language change if the language in the cookies and the language in the url do not match?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question