Accept-Language

Cette traduction est incomplète. Aidez à traduire cet article depuis l'anglais.

Le header Accept-Language de la requête HTTP annonce quels sont les langages que le client est capable de comprendre, et quelle variante locale il préfère. Using content negotiation, the server then selects one of the proposals, uses it and informs the client of its choice with the Content-Language response header. Browsers set adequate values for this header according their user interface language and even if a user can change it, this happens rarely (and is frowned upon as it leads to fingerprinting).

This header is a hint to be used when the server has no way of determining the language via another way, like a specific URL, that is controlled by an explicit user decision. It is recommended that the server never overrides an explicit decision. The content of the Accept-Language is often out of the control of the user (like when traveling and using an Internet Cafe in a different country); the user may also want to visit a page in another language than the locale of their user interface.

If the server cannot serve any matching language, it can theoretically send back a 406 (Not Acceptable) error code. But, for a better user experience, this is rarely done and more common way is to ignore the Accept-Language header in this case.

Header type Request header
Forbidden header name no
CORS-safelisted request-header yes

Syntaxe

Accept-Language: <language>
Accept-Language: <locale>
Accept-Language: *

// Multiple types, weighted with the quality value syntax:
Accept-Language: fr-CH, fr;q=0.9, en;q=0.8, de;q=0.7, *;q=0.5

Directives

<language>
Une langue exprimée sous la forme de 2 ou 3 caractères.
<locale>
A full language tag. In addition to the language itself, it may contains additional information after a '-'. The most common extra information is the country variant (like 'en-US') or the type of alphabet to use (like 'sr-Lat'). Other variants like the type of orthography ('de-DE-1996') are usually not used in the context of this header.
*
Any language; '*' is used as a wildcard.
;q= (q-factor weighting)
Une quantité numérique donnant un ordre de préférence et qui utilise une valeur de qualité relative, appelée poids.

Exemples

Accept-Language: de

Accept-Language: de-CH

Accept-Language: en-US,en;q=0.5

Spécifications

Specification Titre
RFC 7231, section 5.3.5: Accept-Language Hypertext Transfer Protocol (HTTP/1.1): Semantics and Context

Compatibilité des navigateurs

FonctionnalitéChromeEdgeFirefoxInternet ExplorerOperaSafari
Support simple(Oui)(Oui)(Oui)(Oui)(Oui)(Oui)
FonctionnalitéAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Support simple(Oui)(Oui)(Oui)(Oui)(Oui)(Oui)(Oui)

Voir également

Étiquettes et contributeurs liés au document

 Contributeurs à cette page : tuili
 Dernière mise à jour par : tuili,