xHain-hackspace/xhain-website

Switch language based on user preferences

Opened this issue · 1 comments

It is possible to serve the webpage in the user's preferred language without them having to manually toggle the language. Let's do that.

Suggestion

When the user lands their browser language preferences are checked and the matching language is served. I would suggest the following flow. Open to discussion.

  1. If the user has no locale set (or there's an error reading it) -> DE
  2. If English is set -> EN
  3. If multiple are set loop through until DE / EN found
  4. If a locale is set but nor DE or EN -> EN

Currently

The user lands on German landing page by default and manually has to switch to English if they do not g=speak German

https://nanmu.me/en/posts/2020/hugo-i18n-automatic-language-redirection/
https://developer.mozilla.org/en-US/docs/Web/API/Navigator/languages

I'll create a PR when I'm done, but I'm actively working on it, It'll need a small amount of js, but I'll add a noscript alternative as well