4

just wondering if there is a mechanism to "advertise" what values I'd be able to accept in Accept-Language and return a proper Content-Language.

There is "Link: ; rel=alternate hreflang=pt-br", but that forces me to create a new resource (as opposed to exposing the same resource under a different language).

http://www.w3schools.com/tags/att_link_hreflang.asp

Here is a related question:

Content-Language and Accept-Language

Community
  • 1
  • 1
Sam Goto
  • 475
  • 6
  • 11

2 Answers2

1

Ideally this should be done in the HTTP headers - as you guessed, HTML tags are not really the place for this.

About the Content-Type header, from the IETF:

The Content-Language header may list several languages in a comma- separated list.

So the purpose of the Content-Language header is to list ALL the possible languages for the current resource, not just the language of the page you serve.

To advertise your accepted languages, add them all to your Content-Language header.


For example, also from the IETF:

An official European Commission document (in a few of its official
   languages):

      Content-type: multipart/alternative
      Content-Language: da, de, el, en, fr, it
Community
  • 1
  • 1
Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
  • The list is used to represent the "languages used in the document", as opposed to the "languages that the document is available at". Here are examples: A English-French dictionary Content-type: application/dictionary Content-Language: en, fr (This is a dictionary) An official European Commission document (in a few of its official languages): Content-type: multipart/alternative Content-Language: da, de, el, en, fr, it An excerpt from Star Trek Content-type: video/mpeg Content-Language: i-klingon – Sam Goto Aug 03 '15 at 23:21
  • @user453455 I think I understand what you're trying to do now. It seems like you want to read the `Accept-Language` header from the client, then return a document in one of the languages that the client accepts. Like `Content-Language`, `Accept-Language` is also a full list, so the client will be sending you ALL the languages that the user is able to read, and you can pick any one of them for your response. – Maximillian Laumeister Aug 03 '15 at 23:25
  • Are you suggesting that the WEB SERVER uses the Accept-Language to enumerate the languages that it can return as Content-Language? Note that, my client *cannot* enumerate all of the languages the user is able to read (I'd like to learn which languages are *available* from the SERVER). – Sam Goto Aug 04 '15 at 18:16
  • @user453455 That is what I am suggesting, yes. Also your client IS the web browser of the user, unless I'm missing something. – Maximillian Laumeister Aug 04 '15 at 22:16
0

You can achieve this effect with the HTML tag, which uses http-equiv to represent the HTTP header you were desiring.

<meta http-equiv="accept-language" content="de, en">
<meta http-equiv="content-language" content="de">

However, as mentioned in this question, that's really the "poor man's" approach to it, and you should be supplying a proper HTTP header instead:

Content-Language: de
Accept-Language: en, de

If you just want to express what language the webpage is in, then you can use <html lang="de"> too.

Edit: If you're looking to express this properly in the headers, then you can do so by placing a PHP code snippet at the top of your file:

header('Content-Language: de');
header('Accept-Language: de, en');
Community
  • 1
  • 1
Singular1ty
  • 2,577
  • 1
  • 24
  • 39