Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are Content-Language and Accept-Language?

I have seen the HTTP headers of Content-Language and Accept-Language, could someone explain what these are for and the difference between them? I have a multilingual site and wondering should I be setting both to the sites current selected language, by the user.

like image 472
amateur Avatar asked May 27 '11 20:05

amateur


People also ask

What is accept-Language?

The Accept-Language request HTTP header indicates the natural language and locale that the client prefers. The server uses content negotiation to select one of the proposals and informs the client of the choice with the Content-Language response header.

What is content type and accept?

Accept header is used by HTTP clients to tell the server which type of content they expect/prefer as response. Content-type can be used both by clients and servers to identify the format of the data in their request (client) or response (server) and, therefore, help the other part interpret correctly the information.

How do I set accept-Language?

The user can change the Accept-Language header sent by the browser using the browser's preference settings. E.g., in Chrome, go to “Settings”, click on “Show advanced settings...”, scroll down to “Languages”, click on “Language and input settings...”, and then add languages and drag to order them.

How do I know my Language is accepted?

Checking your Accept-Language headers Before changing your preferences you might want to check what your Accept-Language header is currently set to. Run the Internationalization Checker on any page, then in the Information panel, look under Request Headers > Accept-Language .


1 Answers

Content-Language, an entity header, is used to describe the language(s) intended for the audience, so that it allows a user to differentiate according to the users' own preferred language. Entity headers are used in both, HTTP requests and responses.1

Accept-Language, a request HTTP header, advertises which languages the client is able to understand, and which locale variant is preferred.2 There can be multiple languages, each with an optional weight or 'quality' value. For example:

Accept-Language: da, en-GB;q=0.8, en;q=0.7 

(The default weight is 1, so this is equivalent to da;q=1, en-GB;q=0.8, en;q=0.7).

You're going to have to parse the values and weights to see if an appropriate translation is available, and provide the user the translation in the highest preferred language weight.

It is recommended you give the users an alternative, such as a cookie set value, to force a certain language for your site. This is because some users may want to see your site in a certain language, without changing their language acceptance preferences.

like image 105
5 revs, 4 users 46% Avatar answered Sep 30 '22 15:09

5 revs, 4 users 46%