Content-Language HTTP header is utilized to describe the natural language(s) intended for the audience of the HTTP message body. It offers a way for servers to inform clients about the language of the content, enhancing the usability of web content and improving user experience.
Content-Language header field syntax is as follows:
<language-tag> represents a language identifier as defined by BCP 47. A list can also be provided to specify multiple languages.
Usage and Examples
Content-Language header is primarily used in the context of responses to indicate the language of the response content. Here’s an example of a response indicating English content:
HTTP/1.1 200 OK Content-Type: text/html Content-Language: en Content-Length: 1234
In this response,
Content-Language: en declares that the content of the response is in English.
If a resource is intended for a multi-lingual audience, multiple language tags can be listed:
HTTP/1.1 200 OK Content-Type: text/html Content-Language: en, fr, de Content-Length: 2345
Content-Language: en, fr, de indicates that the response content might be equally appropriate for English, French, and German audiences.
Content-Language serves a significant purpose, it’s essential to understand its correct usage. It doesn’t perform any translation or localization tasks; it only informs the client about the language of the provided content.
Also, remember that it’s not recommended to use
Content-Language for language negotiation between clients and servers. Instead, the
Accept-Language request header should be used for determining user language preferences.
Content-Language header should not be confused with the
lang attribute in HTML, which specifies the language of a specific element’s content. Both have separate roles in the context of internationalization.
Content-Language HTTP header is a vital component in the suite of HTTP headers, serving to communicate the language of the content to the client. By correctly leveraging this header, you can enhance the internationalization aspects of your web content and improve usability for diverse user audiences. However, remember that
Content-Language is a descriptive header and does not perform any localization or translation tasks. Always ensure you’re using the right tools for the appropriate tasks when dealing with multi-lingual content.