-
Notifications
You must be signed in to change notification settings - Fork 20
Automatically switch to correct language #77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ch-to-correct-language-np
…ch-to-correct-language-np
| const availableLangs = [ | ||
| {{- range $index, $lang := .Site.Languages -}} | ||
| "{{ $lang.Lang }}"{{ if ne (add $index 1) (len $.Site.Languages) }}, {{ end }} | ||
| {{- end -}} | ||
| ]; | ||
|
|
||
| const langMap = { | ||
| {{- $total := len .Site.Home.AllTranslations -}} | ||
| {{- range $index, $lang := .Site.Home.AllTranslations -}} | ||
| "{{ $lang.Language.Lang }}": "{{ $lang.RelPermalink }}"{{ if ne (add $index 1) $total }},{{ end }} | ||
| {{- end -}} | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation isn't consistent here, isn't it?
| const isVisited = localStorage.getItem('visited'); | ||
| if (isVisited) return; | ||
| localStorage.setItem('visited', '1'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this really the expected behavior @ThomasPe? Or should we store the browser language here and set it every time? In other words, what happens when the user visits the page the next time? Then the language is still wrong, isn't it?
Depending on @ThomasPe answer, let's put 'visited' into a constant to avoid magic string side effects and I would suggest a more explicit name (e.g., 'BrowserLanguageChecked' or similar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to allow the user to switch (back) to any language, so auto-redirect makes only sense on the first page visit? open to other suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would result in an inconsistent behavior, wouldn't it? Let's assume the browser language is English and the default language German. The first time, the user gets redirected to the English version. The second and every time after, the user stays on the German page. I don't see a benefit in the behavior.
Suggestion: we store the preferred language. Initially, the preferred language is the browser language. When the users use the language switcher to change the language, this language is stored as preferred language. Finally, if the preferred language is not the current language, we redirect the user to the preferred language.
This way, users can switch the language with the language chooser and will always end up on their preferred language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good 👍
Checklist
CONTRIBUTING.md)