django-parler-rest
django-parler-rest copied to clipboard
Use request.LANGUAGE_CODE in API
I'm writing an API that needs to return a field localized for the request.
I'm using Django's LocaleMiddleware
, which negotiates the HTTP Accept-language header against settings.LANGUAGE_CODES
and sets the result as request.LANGUAGE_CODE
. Is there a pattern or mixin I should be using on my ViewSet
s to activate that language for the response?
Not that I'm aware of.. Django's LocaleMiddleware
also calls translation.activate()
so the current Django language will be set. django-parler uses django.utils.translation.get_language()
by default when objects are fetched from the database.
You can set the language explicitly off course, using Model.objects.language(..)