Is it possible to override the client accept-language header so that subsequest requests are in a new language?

1.9k Views Asked by At

Our business requirements state that the user should be able to change their language preference without changing their browser or system settings. Our implementation is a simple interface that asks them to choose a language. Originally, I was going to just store their choice in a cookie value and check for it and set the UI Culture, but I am wondering if there is an easier way.

At the moment, I'm trying to see if I can just accept their choice and then set the accept-language in the response so that it will be used in subsequent requests. Right now, I set the accept-language header in the response, but the next request overwrites it with browser values (e.g. en-US,en;q=0.8") Is this possible and how do I go about it? Any other ideas to achieve this functionality is also welcomed.

1

There are 1 best solutions below

0
On

Yes, you can override the effect of the Accept-Language HTTP header. More exactly, such a header has no effect as such. Its only role is to participate in language negotiation if the server does such negotiation. You need not use anything to override it; just don’t use it, or use it in a manner that makes other settings override it.

Using a cookie is common method. Not ideal, but often the best approach in practice. If desired, you can use the Accept-Language header to determine the default option in a language selection menu, but this is more complicated than most people think. The header specifies, in general, a list of languages, or locales, with “quality factors”, not just a language.

There is no point in setting Accept-Language in an HTTP response, since Accept-Language is a request header only.