Skip to content
Grav 2.0 is officially stable. Read the announcement →

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Support

English translation of the langswitcher suddenly not working

Solved by pamtbaau View solution

Started by werdi 6 years ago · 17 replies · 839 views
6 years ago

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!

6 years ago

@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?

6 years ago

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

6 years ago

@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...

6 years ago

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.

last edited 06/14/20 by werdi
6 years ago

@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.
6 years ago

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.

YAML
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

<br/>

@pamtbaau:
And check if there are any relevant configurations settings for the plugin.
(You didn’t mention which language plugin you are using).

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

<br/>

@pamtbaau:
Inspect the relevant git commits with respect to file system.yaml

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

<br/>

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?

6 years ago

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

6 years ago

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

6 years ago

@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?

6 years ago

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

6 years ago

@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...

6 years ago

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

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?

6 years ago

@pamtbaau I solved it.

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

6 years ago Solution

@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:

YAML
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

last edited 06/28/20 by pamtbaau
6 years ago

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

I changed the code to

TXT
http_accept_language: false

Does this solve the issue now?

6 years ago

@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
6 years ago

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

Suggested topics

Topic Participants Replies Views Activity
Support · by Thomas, 1 week ago
2 60 16 hours ago
Support · by Anna, 3 days ago
2 66 19 hours ago
Support · by Justin Young, 20 hours ago
1 34 20 hours ago
Support · by Duc , 1 week ago
2 70 6 days ago
Support · by Colin Hume, 1 week ago
2 61 6 days ago