chinleung / laravel-multilingual-routes

A package to handle multilingual routes in your Laravel application.
https://github.com/chinleung/laravel-multilingual-routes-demo
MIT License
401 stars 25 forks source link

Enhance language detection middleware #15

Closed romanzipp closed 4 years ago

romanzipp commented 4 years ago

Update Laravel request language extraction to use the getPreferredLanguage method since the locale property on the Symfony request class has protected access.

romanzipp commented 4 years ago

Got it! I've misunderstood the usage of the magic attribute $request->locale. The latest change should comply with your requested changes.

chinleung commented 4 years ago

@romanzipp I had to revert the changes because now that I think of it, we don't want to change the locale based on the Accept-Language header. For instance, my website has a / which is in French, and a /en/ in English, I would not want my root path to be displayed in the header's locale, which is English.

romanzipp commented 4 years ago

I've resolved this issue for myself by

chinleung commented 4 years ago

I've resolved this issue for myself by

  • storing a cookie with the currently preferred language
  • redirecting the landing page to a specific language (/en, /de)

@romanzipp What if the primary locale has no prefix? For instance, / content should be loaded in fr and /some-slug should be in fr too. 🤔