getgrav / grav-plugin-langswitcher

Grav LangSwitcher Plugin
https://getgrav.org
MIT License
28 stars 26 forks source link

When `http_accept_language` is set to true, manual switching does not work #64

Closed kees-closed closed 2 years ago

kees-closed commented 2 years ago

When I add the language switcher to my website, but enable http_accept_language in config/system.yml, clicking on anything else than the browser preferred language will fall back to the browser preferred language.

langswitcher preferences:

enabled: true
built_in_css: true
untranslated_pages_behavior: none
language_display: long

Is there a way to automatically set the language of the browser, but allow a user to switch to another language through the langswitcher plugin? Now these options seem to be fighting. And the http_accept_language wins every time.

mahagr commented 2 years ago

If you want to use that setting, you need to also make sure you have these (or at least one of them):

system.yaml

languages:
  include_default_lang: true     # Include the default lang prefix in all URLs
  session_store_active: true     # Store active language in session

I generally prefer the first option as it keeps languages separated (eg. url based).

kees-closed commented 2 years ago

Seems like it only works when include_default_lang is enabled as well.

languages:
  supported:
    - nl
    - en
  default_lang: nl
  include_default_lang: true
  include_default_lang_file_extension: true
  translations: true
  translations_fallback: true
  session_store_active: true
  http_accept_language: true
  override_locale: true
  pages_fallback_only: false
mahagr commented 2 years ago

Yeah, as I said, it's the best way. I think both the session and HTTP options require all languages to have their own path to work properly. You can properly make it work without, but it is such a mess that I wouldn't even try. It will never work fully as expected and it will cause major issues with search engines when indexing.