Reputation: 1554
I was wondering how the string of HTTP_ACCEPT_LANGUAGE
is determined.
if a user has the following string:
"HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.9,he;q=0.8"
SideQuestion: Is there any part of an HTTP request to get the OS language?
I went over google, but I couldn't understand the q=n
quality value, please please, please don't copy google or PHP.NET, I can search and read also, I would like to understand and make the best of using the most of an http request.
Thanks, Bud
Upvotes: 2
Views: 2388
Reputation: 549
Adding to @Yuankun's answer re the 'q' values, looking at RFC7231 section-5.3.5 (which Obsoletes RFC 2616) it seems that is not quite correct.
It should be <language-range>;<quality>, ...
such that an example string
en,en-US,en-AU;q=0.8,fr;q=0.6,en-GB;q=0.4
ends up as
en;q=1
en-US;q=1
en-AU;q=0.8
fr;q=0.6
en-GB;q=0.4
Upvotes: 4
Reputation: 7813
Generally speaking, Accept-Language
can be used in one of the following forms:
Accept-Language: *
, which means you are ready to accept any language.Accept-Language: <language>
, where <language>
stands for the language code, usually 2 letters.Accept-Language: <language-locale>
, where <language-locale>
can be seen as an extended form of <language>
,"en-US,en;q=0.9,he;q=0.8"
.how are these comma separated parameters determined (OS, browser, IP->geo?)
The default value is retrieved from OS language settings by the browser.
And users can manually set preferred language(s) from browser's settings panel. If multiple languages are set, their order being the order in Accept-Language
as you see.
what do those params mean?
They are a list of <quality>-<language>
pairs, separated by ;
.
Default quality is 1, so your Accept-Language
value actually is:
q=1,en-US,en;q=0.9,he;q=0.8,rest of languages...
Is there any part of an HTTP request to get the OS language?
No.
I couldn't understand the q=n quality value.
As explained.
Upvotes: 3
Reputation: 53601
The string is determined by the client software. The client can request whatever languages it wants, with whatever priorities it wants. The server is not obliged to comply.
The rules that describe the format of the string can be found here.
The quality value denotes priority, with higher values sorting first. By your example, servers answering this request should attempt to provide English as a first choice, then Hebrew.
You probably don't need to parse this yourself. You can likely use something like locale_accept_from_http().
Upvotes: 1