acceptedlanguages.js icon indicating copy to clipboard operation
acceptedlanguages.js copied to clipboard

Internet Explorer doesn't return the Accept-Language information

Open CJDennis opened this issue 7 years ago • 6 comments

The results from Internet Explorer are nothing like the actual Accept-Language headers send.

From http://validator.w3.org/i18n-checker/, I get "fr-FR, fr, en-AU, en, si, ru, he" but from the library I get "en-AU", which isn't even the first language I specified.

CJDennis avatar Aug 08 '17 11:08 CJDennis

Thanks for rewiring the issue. Could you share the html that you are including it in? And what version of internet explorer are you using?

leighmcculloch avatar Aug 08 '17 14:08 leighmcculloch

The library will give you the accepted, alternate and relevant languages. accepted is the languages that the user's browser is configured as the preferred languages of the user. alternate is the languages supported by the web page, as defined in it's link relations. relevant is the intersection of the two.

leighmcculloch avatar Aug 08 '17 18:08 leighmcculloch

<!DOCTYPE html>
<html>
  <head>
    <title>Page Title</title>
    <script type="text/javascript" src="acceptedlanguages.min.js"></script>
  </head>
  <body>
    <div id="accepted"></div>
    <div id="alternate"></div>
    <div id="relevant"></div>
    <script type="text/javascript">
      document.getElementById("accepted").innerHTML = "Accepted: " + acceptedlanguages.accepted.join(", ");
      document.getElementById("alternate").innerHTML = "Alternate: " + acceptedlanguages.alternate.join(", ");
      document.getElementById("relevant").innerHTML = "Relevant: " + acceptedlanguages.relevant.join(", ");
    </script>
  </body>
</html>

Output:

Accepted: en-AU
Alternate: 
Relevant: 

Internet Explorer 11, Windows 10

Languages installed in Windows: English (Australian), French, Sinhala, Russian, Hebrew

From http://validator.w3.org/i18n-checker/:

Request headers: Accept-Language fr-FR fr en-AU en si ru he
Code: Accept-Language: fr-FR,fr;q=0.9,en-AU;q=0.7,en;q=0.6,si;q=0.4,ru;q=0.3,he;q=0.1 

CJDennis avatar Aug 09 '17 13:08 CJDennis

If I set French as the first language, I get:

Accepted: fr-FR
Alternate: 
Relevant: 

CJDennis avatar Aug 09 '17 13:08 CJDennis

Apparently, it's not possible in all browsers to get the Accept-Language field without making a request and getting the server to echo the header back to you.

CJDennis avatar Aug 13 '17 05:08 CJDennis

Agreed. I guess it's a trade off. A request could be made but then that shows down decisions that can be made about the languages in the frontend. I can add a request to the library that gets the full proper accepted languages list and makes it available. What do you think?

leighmcculloch avatar Aug 13 '17 06:08 leighmcculloch