#32922: Adding "preferred_language" property to "HttpRequest" object
-----------------------------------------+------------------------
Reporter: pixel365 | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
Sometimes it is useful to get the client's preferred language from the
request and then pass it somewhere, for example, apply a filter to fetch
data.
Therefore, it is useful to access this property in the object.
{{{
@property
def preferred_language(self):
"""Returns the client's language in order of priority from the
"Accept-Language" header"""
languages = [_.strip() for _ in self.headers.get('Accept-Language',
'*').split(',')]
for language in languages:
if language.split(';')[0] == language:
return language
return language.split(';')[0]
return '*'
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32922>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/051.dda1fad855c792dec2041b28b6f20448%40djangoproject.com.