HTTP headers | Accept-Language
This HTTP Accept-Language header tells the server about all the languages that the client can understand. With the help of content negotiation, there will be a set of supported languages in the HTTP Accept-Language proposal then the server selects one of the proposals of those languages and place that in the content-language header. In a few cases users can change the languages manually otherwise server detects the supported language by the browser’s language. But remember one thing that it is recommended that the server never overrides an explicit decision. If the user is comfortable with a language that does not list on the server language then the server can not serve the matching language to the client in that case 406 Not Acceptable status code will be sent.
- This is the specific language selection syntax.
- This syntax works as a wild card (selects all languages).
Note: Multiple languages can be listed by using commas and the optional.
Directives: This header accepts two directives as mentioned above and described below:
- <language>: This consists of a 2-3 letter base language tag representing the language, followed by sub-tags separated by ‘-‘ . The extra information is the region and country variant (like ‘en-US’ or ‘fr-CA’)
- *: It is used as a wildcard for any language present.
Note: The ;q= it defines the factor weighting, value placed in an order of preference expressed using a relative quality value
To check this Accept-Language in action go to Inspect Element -> Network check the request header for Accept-Language like below, Accept-Language is highlighted you can see.
Supported Browsers: The browsers are compatible with HTTP Accept-Language header are listed below:
- Google Chrome
- Internet Explorer