getgrav / grav

Modern, Crazy Fast, Ridiculously Easy and Amazingly Powerful Flat-File CMS powered by PHP, Markdown, Twig, and Symfony
https://getgrav.org
MIT License
14.48k stars 1.4k forks source link

Default language not reachable with http_accept_language enabled and include_default_lang: false #509

Closed PeterSiegl closed 8 years ago

PeterSiegl commented 8 years ago

Looks like there is a bug using the http_accept_language option with include_default_lang: false.

Let's say the default language is english and the configuration in the system.yaml looks like this:

  session_store_active: true
  http_accept_language: true
  include_default_lang: false

If I set the browser language to e.g. german, grav redirects me correctly to the german page version. But if I want to switch back to the english version (the default language without the language slug in all urls) I always get redirected to the german version. If I set include_default_lang to true (the default language slug appears in the url again) everything works fine. Any ideas?

flaviocopes commented 8 years ago

Replicated on the Multilang Skeleton, with this configuration it does not go back to the site default language.

When clicking on the English link (default lang) when the browser lang is != english, it redirects to the browser language. All the other links work fine. So I guess it's just a problem with the default lang.

flaviocopes commented 8 years ago

After inspecting the code, it's by design. Grav determines the language by the URL, so if no lang is set in the URL, and http_accept_language is true, it gets the browser language.

The only way to work in this situation is to have include_default_lang true.

SirNovi commented 8 years ago

Maybe this could be turned into a feature request.

There's also the session_store_active: true - Shouldn't it be possible to extend that functionality in a way that allows the user to manually set the preferred language just by switching to another language after it got redirected to the browsers language once?

To clarify an example on how the optimal functionality would look like in my opinion:

  1. User opens website.com
  2. Websites checks browsers preferred language and forwards user to website.com/fr
  3. User manually changes the language to English which is found under website.com
  4. Grav acknowledges the decision and sets the active language for this session to the chosen one (english)
PeterSiegl commented 8 years ago

@SirNovi Yeah exactly, that'd be great! :+1:

@flaviocopes Okay... can you think of a workaround? Could I do the language detection myself (get browser lang, select lang, create cookie resp. check cookie) and somehow set the active language before Grav starts to render the website?

lfaoro commented 8 years ago

Please, can we have an ETA for fixing this or at least a workaround we can use?

rhukster commented 8 years ago

Can someone please test this again with latest Grav 1.1 beta?

flaviocopes commented 8 years ago

The current behaviour is this: if a user reaches site.com, it's redirected to the browser language page, if existing, or if not, it sees the default language.

From site.com/it (for example), if I type site.com in the browser, I'm redirected to my language page (site.com/it). 🆗

If I click site.com/en, I see site.com in english, as I chose english. If now I go back to site.com, I will see the english version of the site. 🆗

So this now plays well with the language chooser plugin, or simply having a flag that points to site.com/en (of course, you can change /en with the default language)

lfaoro commented 8 years ago

The current behavior I'm experiencing is quite different. Whatever language I switch to going back to site.com returns to the default language.

e.g. site.com/it I see site.com in Italian - now if I go back to site.com I see it in English (default), my language preference doesn't persist.

flaviocopes commented 8 years ago

Could be your system settings? What's your system.yaml file content?