English translation of the langswitcher suddenly not working

Hey there,

Suddenly, the English button falls back always to German. It’s like it’s non-existent.

I did change some settings in the last few days but nothing that I thought would affect the langswitcher plugin.

Could someone look into this? Site is: www.mariabusque.net

Thanks!

@werdi, Do you mean that the language of the consent popup and its button is always in German while the default language is English?

Are you using a plugin to show the consent popup?

@pamtbaau I mean the langswitcher, not the consent popup. I’m using code for the consent popup, you can see it in the code.

@werdi, I asked about the consent popup because I didn’t notice anything wrong about the language selector.

My system has English as language and the site opens in English. When choosing any language it switches to the correct language.

The consent popup should be in English though…

That is funny because I cannot access the English version of the site. Something seems to be blocked. Clicking the English button brings the site to the German version, always.

the consent popup is in German because I could only show in one language, so I chose German.

@werdi, Just set the preferred language in my browser to be German and I can reproduce your findings. The site opens in German, and when selecting the English language, the site remains in German. Selecting Espanol works fine.

Suggestions:

  • Check the language settings in system.yaml
    Would you mind sharing them?
  • Inspect the relevant git commits with respect to file system.yaml
  • And check if there are any relevant configurations settings for the plugin.
    (You didn’t mention which language plugin you are using).
    Inspecting the code of your site I expect grav-plugin-langswitcher, which doesn’t seem to have any relevant settings.

These are the language settings in /user/config/system.yaml - there’s another system.yaml in the config folder, but I’m guessing you asked for this one.

languages:
  supported:
    - en
    - de
    - es
  default_lang: null
  include_default_lang: false
  pages_fallback_only: false
  translations: true
  translations_fallback: true
  session_store_active: false
  http_accept_language: true
  override_locale: false

I’m using the langswitcher plugin, don’t understand the question.


I’m afraid I don’t know how to do that.


Also, I did change something last week which was to (try to) change the Default Language Prefix. That didn’t seem to work though. Could that be interfering?

@werdi, Could it be that your English page files do not have the en language indicator? Like default.md instead of default.en.md

I checked and they’re all there, otherwise you couldn’t see them on your end, right?

@werdi,

… otherwise you couldn’t see them on your end, right?

If the requested language does not have a matching page with the correct language extension, Grav will fallback to the first language in the list of languages.supported (which is German in your case), and if that doesn’t exist, it will look for the second in the list, etc.

How do the language extension of the pages look like?

They look just like default.en.md (or did I understand your question correctly?)

@werdi, I cannot reproduce the issue on a fresh Grav 1.6.26 installation with your language settings and correct language extension for the pages.

Only when the language extension of English is incorrect, I can reproduce the behaviour of your site.

I’m sorry, but I’m out of suggestions…

I updated my Grav package to see if it would change anything…

I know I changed something in some file. (And I know that is not useful at all.) I kept trying to tell Grav to not jump into the English version when I start the site. This kept happening, although I had somewhere already set it up so that German is the first language of the site. Is there anywhere else one can influence the language settings?

@pamtbaau I solved it.

I changed the order of the languages as they appeared in the system.yaml file.

@werdi, I’m afraid you ‘sort of’ solved it… You solved it for a visitor whose browser is set to German.

The issue appears when using the following combined setting:

http_accept_language: true
include_default_lang: false

This is a reasonable combination, so I tend to think this might be a bug in Grav.

With above combination, the language mentioned first in the supported list will always be ignored and replaced with the language set by the browser.

In your case, where de is mentioned first, German will be ignored when the browser is set to either English or Spanish and replaced with the browser’s preference.

Solution (sort of):
Changing the value of either of the two settings will fix the problem, but then you will loose your preferred setting.

The bug:
I think this is an issue in Grav and not the langswitcher plugin, because without the plugin the same happens. In my default site, with your config and with browser set to Spanish the following happens:

  • localhost/de/typography -> localhost/es/typograpy (= wrong)
  • localhost/en/typography -> localhost/en/typograpy
  • localhost/es/typography -> localhost/es/typograpy

I’ve logged the following issue #2948

@pamtbaau Thanks so much for taking a look into this.

I changed the code to

http_accept_language: false

Does this solve the issue now?

@werdi, All seems to be working fine.

  • The pages I have tested are accessible for all its available translations.
  • The language switcher switches to the right translation.
  • The preferred language set in the browser does not cause any trouble anymore.

But of course, the user does not get redirected to his/her preferred translation anymore. But that’s the compromise…

1 Like

@pamtbaau Agreed. It’s the compromise. Thanks for taking the time.