Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the order of the languages matter in the HTTP Accept-language field?

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.

like image 241
user2159121 Avatar asked Oct 02 '22 15:10

user2159121


2 Answers

No, the ordering does not matter.

like image 117
Julian Reschke Avatar answered Oct 13 '22 11:10

Julian Reschke


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

like image 44
ioquatix Avatar answered Oct 13 '22 12:10

ioquatix