Jordy
Jordy

Reputation: 4809

Which http headers should I set for multi language site?

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!

Upvotes: 4

Views: 3410

Answers (1)

CodeCaster
CodeCaster

Reputation: 151674

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

Upvotes: 4

Related Questions