I was wondering if the order of the actual languages in the Accept-language matters. For example, if our HTTP GET message contained the header:
Accept-Language: en-us, en-gb;q=0.2, en;q=0.3, fr, fr-ch, da, fi
...would the browser prefer Traditional French (fr) over Swiss French (fr-ch) even though they both have no Relative Quality Factor q mentioned, and hence would be 1.
No, the ordering does not matter.
When I implemented this, I used a stable sort so that values with the same relative q-value would stay in the same relative order. I believe this is logical and probably reflects the intention of the spec:
Note that some recipients treat the order in which language tags are listed as an indication of descending priority, particularly for tags that are assigned equal quality values (no value is the same as q=1). However, this behavior cannot be relied upon. For consistency and to maximize interoperability, many user agents assign each language tag a unique quality value while also listing them in order of decreasing quality. Additional discussion of language priority lists can be found in Section 2.3 of RFC4647.
As an example of where this behaviour might be desirable, if you have a caching layer/middleware and you are handling the Accept*
headers in an unstable way (e.g. possibly random selection if they all have the same q-value), while you might not be technically doing anything wrong, but the results would be unpredictable and it might cause problems in the caching layer and a poor user experience (e.g. language changing between pages for no obvious reason).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With