4

I'm currently working on a multilanguage site and this is my situation:

According to answers in this and this article I need to set a http-header too, but I can't figure out how to do this and what kind of header I should set. Is it the Accept-Language or the Content-Language? And is it really a must to set a http-header for multi-language websites? And is Accept-Language a request and not a response?

Please help! Thank you!

Community
  • 1
  • 1
Jordy
  • 4,719
  • 11
  • 47
  • 81
  • So why are they talking in the answers about setting the HTTP headers? And how to do it the right way? – Jordy Apr 28 '16 at 20:56
  • Because the `Accept-Language` _request_ header indicates the language settings and preferences of the user agent, and might be used to redirect to, or serve, a document in a specific language. – CodeCaster Apr 28 '16 at 21:00
  • Yes I understand, but they are talking about '**responding** with a Vary header', so that I have to do something. – Jordy Apr 28 '16 at 21:04
  • It's still not clear for me if I have to use the Vary header or not (see comments under your answer too). – Jordy Apr 29 '16 at 17:09

1 Answers1

4

And is it really a must to set a http-header for multi-language websites?

From HTTP headers, meta elements and language information - W3.org:

When specifying the language for text-processing you are declaring the language in which a specific range of text is actually written, so that user agents or applications that manipulate the text (such as voice browsers, spell checkers, or style processors) can effectively handle the text in question.

So yes, it makes sense from a usability standpoint to declare the language used on a page, and the language of the intended audience of a page.

For how to specify this, see the same page:

The HTTP Content-Language header can be used to provide metadata about the intended audience of the page, and can indicate that this is more than one language. The Content-Language value for an http-equiv attribute on a meta element should no longer be used. You should use a language attribute on the html tag to declare the default language of the actual text in the page.

And HTML meta tag for content language:

should really be expressed in the headers. For example:

Content-language: es

The Accept-Language is not a response header but a request header, so with both Content-language as response header and the <html lang=""> attribute in the HTML element you're good to go.

As for the Vary: X, Y response header: this means that the response to the current request URI will differ when headers X or Y differ.

This is for example important when doing a redirect. Say on your landing page, you determine where to redirect based on the Accept-Language request header:

GET / HTTP/1.1
Host: example.com
Accept-Language: en

Your site will then redirect to the English subsite:

HTTP/1.1 302 Found
Location: http://example.com/en
Vary: Accept-Language

This will tell the user agent (browsers, search engines) that requesting the same URI with a different Accept-Language will yield a different result. For example:

GET / HTTP/1.1
Host: example.com
Accept-Language: es

Your site will then redirect to the Spanish subsite:

HTTP/1.1 302 Found
Location: http://example.com/es
Vary: Accept-Language
Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • Thank you! So I don't have to set a Vary header (related to language) at all in my multi language site? – Jordy Apr 28 '16 at 21:02
  • You use the Vary header if the response ... varies per request header. You'd use that when the URI remains the same, but the resulting response differs by looking at the Accept-Language request header (and so also when basing the redirect on that). – CodeCaster Apr 28 '16 at 21:08
  • Thanks, so I need to set it when the URL is always the same (so that http://www.example.com displays different content for Spanish and French users). And also when I redirect users to http://www.example.com/es/ or another url depending on their language (that is my case)? – Jordy Apr 28 '16 at 21:18
  • The vary header tells the user agent: you're going to get a different response when the specified headers change. `Vary: Accept-Language` will tell the user agent that requesting with a different language will yield a different result on the same URI. – CodeCaster Apr 30 '16 at 09:57
  • Yes I understand that, but I don't need it when the url for every language is different? (http://www.example.com/en/ and http://www.example.com/es/) – Jordy Apr 30 '16 at 12:43
  • Yes, thank you very much! It's just so strange that there isn't any multi-language website (and I tested it with +-50 websites) that sends a `Vary: Accept-Language` response (like Facebook, Microsoft, Apple, Airbnb, ...) – Jordy Apr 30 '16 at 15:26
  • Content-Language is not really necessary: http://stackoverflow.com/questions/5423989/proper-use-of-php-headercontent-language – Jordy Jun 06 '16 at 20:14
  • @Jordy indeed not necessary, but it is informational. Browsers may ignore it, but other systems may utilize it. – CodeCaster Jun 06 '16 at 20:30