Suggestion: Use language negotiation to populate the list of languages
I took a look at the new website at https://www.peppercarrot.com/2021/ and have a suggestion regarding the language bar at the top.
How about using the ‘Accept-Language’ header sent by the browser to populate the default list of languages? Relevant documentation:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language https://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4
So if the browser sends the following header
Accept-Language: nn,da;q=0.9,fr;q=0.8,de-CH;q=0.7,xx;q=0.5,sv;q=0.3,*
The list of languages would be:
Norwegian Nynorsk | Danish | French | German | Swedish | ...
Some notes:
- The language ‘xx’ should be ignored, as there isn’t a P&C translation for this language.
- The suffix ‘CH’ in ‘de-CH’ is ignored. In general, all country-specific suffixes can be ignored, as P&C doesn’t yet have country-specific translations (AFAIK).
- Any duplicates should be ignored (e.g. ‘en-GB,en-US,de,en,fr’ → ‘en,de,fr’).
- The ‘...’ at the end can be filled with the current default languages not already shown (English, Spanish etc.).
- If no language cookie is set, the page should default to the first available translation in the
Accept-Language
list.
You can see which Accept-Language
header your browser sends at https://www.whatismybrowser.com/detect/what-http-headers-is-my-browser-sending.