Hello, I’m currently using a websocket in my app and I need to know the user default browser language in it.
I found a solution for http request : request.LANGUAGE_CODE
(python - get Default language of browser in Django - Stack Overflow).
But I found nothing similar with channel. Any idea on how to do it ? Maybe using self.scope
somehow ?
Note - request.LANGUAGE_CODE
is the “active language” in Django, it is not the browser’s default language.
I think what you’re looking for would be in the Accept-Language
header. (See get_language_from_request
and parse_accept_lang_header
in django.utils.translation.trans_real
)
If that information is available in a header in the request, it would be available to you at scope['headers']
.
1 Like
Thank for your reply, looking at scope['headers']
, the accept-language
contain all accepted language by order of preference. So that was indeed the solution.