1. HTTP (Hypertext Transfer Protocol)

  1. HTTP Headers

  1. Accept-Language
    1. Writing requests (clients)
    2. Reading requests (servers)
    3. Overview table
    4. Syntax
    5. Examples
    6. Implementations
      1. Node.js
    7. History

Accept-Language

The Accept-Language header specifies which (natural) languages the user would prefer to receive.

The value is one or more RFC5646 language tags with an optional q-value to indicate preference.

Writing requests (clients)

Clients use the Content-Language header to indicate the media type responses the user is capable of reading, and order of preference. This should be configurable by the user, either directly, or read from a system setting; if no preference is known, it is better to omit this header.

Reading requests (servers)

Use the Accept-Language header in cases where multiple versions of a resource are available and the server wants to serve a version the user is likely to understand. This does not happen often; typically, users linking to a resource want to link to the resource in that language, and if another user needs a translation, they can consult a list of translations (for example, see Wikipedia).

Cases where this header should be used is a language selection screen, for example, the landing page of an international corporation website:

  1. The resource can return a localized page asking the user to confirm their language; the selected version should be identified with a Content-Location header, and the server must add a Vary header of Vary: Accept-Language.

  2. The resource can automatically redirect the user to the localized version of the website, using a 303 See Other and a Vary: Accept-Language header.

The server can also suggest translations to the client using a hreflang link attribute in a rel="alternate" link, see Content-Language for more information.

Overview table

Name
Accept-Language
Description
Specifies the (natural) languages preferred by the user.
Direction
Request
Negotiates
Content-Language
List usage in
Vary
Specification
RFC 9110: HTTP Semantics §5.3.5. Accept-Language

Syntax

Accept-Language = #( language-range [ weight ] )
language-range  = <language-range, see [RFC4647], Section 2.1>
weight = OWS ";" OWS "q=" qvalue
qvalue = ( "0" [ "." 0*3DIGIT ] )
        / ( "1" [ "." 0*3("0") ] )

Examples

A request where the user prefers Danish, then British English, or finally any variation of English:

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

Implementations

Node.js

  • accept
  • negotiator

History

  1. 1999-06: RFC 2616 §14.4. Accept-Language. This version requires at least one item in the list.
  2. 2014-06: RFC 7231 §5.3.5. Accept-Language
  3. 2022-06: RFC 9110 §12.5.3. Accept-Encoding